After configuring my tsconfig.json
, I can now use short import paths in my code for brevity. This allows me to do things like
import { FooService } from 'core'
instead of the longer import { FooService } from '../../../core/services/foo/foo.service'
.
Everything was working fine until I created a new file and encountered an error with one of the imports:
Cannot find namespace 'environment'.
The error is triggered by this line:
import { environment } from 'environment';
It's puzzling because all my other services have the same import without any issues, the error only pops up in this newly created file.
Here is a snippet of my tsconfig.json
:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"paths": {
"core": ["app/core"],
"core/*": ["app/core/*"],
"shared": ["app/shared"],
"shared/*": ["app/shared/*"],
"modal": ["app/modal"],
"modal/*": ["app/modal/*"],
"environment": ["environment/environment"] // The problematic line
},
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016",
"dom"
]
}
}
The paths
seem correctly set up, so it's perplexing why only this file is throwing an error. Can anyone shed light on how to resolve this issue?