Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Angular project won't compile with strict mode

Generated Angular project with CLI Modified tsconfig, added strict options

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "strict": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": ["node_modules/@types"],
    "lib": ["es2017", "dom"]
  }
}

When running ng serve I get following error:

ERROR in src/app/app.component.ts(2,29): error TS7016: Could not find a declaration file for module 'util'. 'D:/proj/node_modules/util/util.js' implicitly has an 'any' type. Try npm install @types/util if it exists or add a new declaration (.d.ts) file containing declare module 'util';

I tried npm install suggested - this module does not exist. I also tried to delete node_modules and do npm install. Same thing. Any pointers?

EDIT

app.component.ts

import { Component, OnInit } from "@angular/core";
import { isUndefined } from "util";

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.scss"]
})
export class AppComponent {
  title = "Portal";
}
like image 638
katit Avatar asked Mar 30 '18 15:03

katit


People also ask

Why we use -- no strict in Angular?

Strict mode improves maintainability and helps you catch bugs ahead of time. Additionally, strict mode applications are easier to statically analyze and can help the ng update command refactor code more safely and precisely when you are updating to future versions of Angular.

How do I enable this strict feature in Angular 10?

To opt into the strict mode, you need to create a new Angular CLI app, specifying the --strict flag: The command above will generate a workspace with the following settings enabled on top of the defaults: Strict mode in TypeScript, as well as other strictness flags recommended by the TypeScript team.

How do I turn off strict mode in Angular 10?

Disable strict checks entirely by setting strictTemplates: false in the application's TypeScript configuration file, tsconfig. json. Disable certain type-checking operations individually, while maintaining strictness in other aspects, by setting a strictness flag to false.

Where is strict mode in Angular?

Enabling Angular strict mode through the Angular CLI will enable TypeScript strict mode in your app also as enable some Angular strict checks. Angular Strict template checking is enabled via strictTemplates in tsconfig. json . It'll force the Angular compiler to check tons of things.


1 Answers

try this:

1: Delete node_modules

2: Run npm install

3: Run ng serve --aot=false

Hope it will help you.

like image 160
Shubham Verma Avatar answered Nov 09 '22 01:11

Shubham Verma