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 containingdeclare 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";
}
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.
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.
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.
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.
try this:
1: Delete node_modules
2: Run npm install
3: Run ng serve --aot=false
Hope it will help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With