我已经配置了我的tsconfig.json,所以我可以在我的代码中使用简短的导入路径以简化.例如,我可以从’core’导入{FooService},而不是从’../../../core/services/foo/foo.service’强制执行import {FooService}之类的操作.
这工作得很好,除了某些原因我现在已经创建了一个新文件,其中一个导入错误:
Cannot find namespace ‘environment’.
由于以下行发生此错误:从’environment’导入{environment};
这很奇怪,因为我在许多其他服务中都有相同的导入,并且没有一个抛出错误,它只发生在我创建的这个新文件中.
这是我的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"]// HERE },"sourceMap": true,"declaration": false,"moduleResolution": "node","emitDecoratorMetadata": true,"experimentalDecorators": true,"target": "es5","typeRoots": [ "node_modules/@types" ],"lib": [ "es2016","dom" ] } }
如您所见,路径设置正确.如果它们不是,它将无法在其他文件中一直工作……
这里发生了什么?有人知道怎么修这个东西吗?