After updating a project from Angular 8.2 to version 10, I followed the instructions on https://update.angular.io/ and everything seemed fine. However, once I implemented Path Mapping, I started encountering this error everywhere:
Cannot find module '@environments/environment' or its corresponding type declarations.ts(2307)
This error specifically affects @environments and @modules which are declared in the paths. The other modules do not show any errors because they are not being used.
Currently, the project builds correctly using ng build without any errors, but when using ng build --prod, Visual Studio Code (v1.46.1) displays import errors. Here is what I have:
src/tsconfig.json
{
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./e2e/tsconfig.json"
}
]
}
src/tsconfig.app.json
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outDir": "./lw/app",
"types": []
},
"files": ["src/main.ts", "src/polyfills.ts"],
"include": ["src/**/*.d.ts"],
"exclude": ["src/test.ts", "src/**/*.spec.ts"]
}
src/tsconfig.base.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "src",
"outDir": "./dist/lw",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "es2020",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"emitDecoratorMetadata": true,
"noImplicitAny": false,
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "dom"],
"paths": {
"@angular/*": ["./node_modules/@angular/*"],
...
}
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictTemplates": true,
"strictInjectionParameters": true
}
}
NOTE: I have tried various baseUrl configurations without success.
Build Result
$ ng build
Generating ES5 bundles for differential loading...
ES5 bundle generation complete.
...
VSCode info
Version: 1.46.1 (user setup)
Commit: cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
Date: 2020-06-17T21:13:20.174Z
Electron: 7.3.1
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Windows_NT x64 10.0.18363
Angular CLI
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ...
...
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.1000.1
...
typescript 3.9.6
webpack 4.43.0
Here is an image showing the organization of my project:
https://i.sstatic.net/uYqW7.png
In addition, a strange issue arises where certain services, such as CityService, do not show any errors and can be accessed without problems, while other services like ColorService display errors despite having a similar structure.