Error:
src/app/app.component.ts:4:12 - error TS2591: Cannot find name 'module'. Do you need to install type definitions for node? Try
npm i @types/node
and then addnode
to the types field in your tsconfig.4 moduleId: module.id,
When attempting to run "ng build" to compile my Angular files, I encounter an error for every instance of the variable "module" being used. Despite knowing that the module exists, as it is visible in the node_modules folder and I can navigate to its file by ctrl+clicking on it.
I have already tried deleting the entire node_modules directory and reinstalling.
I have not made any changes to my tsconfig.json file since I am still a beginner. Here is the content of the file:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
An example of how "module" is used in a TypeScript component:
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'app',
templateUrl: 'app.component.html'
})
export class AppComponent { }
There may be an issue with my project structure, as I am unsure about the correct structure to use. I am working on a Spring + Angular application with the following setup:
The angular app structure should be fine since it was generated using the ng new command.
The output path in angular.json is specified as "outputPath": "../public", which should be inside the resource directory.
If you have any suggestions or ideas on what might be causing this issue, please let me know.