【发布时间】:2020-08-20 03:46:56
【问题描述】:
当我尝试构建一个 Angular 项目时,我遇到了这个问题:
文件 '/angular/src/environments/environment.ts' 不是模块
我像这样导入文件:
import { environment } from '../../environments/environment';
我的tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
在我的环境文件夹中,我有文件:environment.ts、environment.prod.ts、environment.dev.ts。
我使用 NODE_VERSION=10,NG_CLI_VERSION=8
我的 angular.json,build.configurations for dev :
"dev": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"serviceWorker": true
}
构建命令:"build": "ng build --configuration=dev --aot",
请帮助我。提前致谢!
【问题讨论】:
-
你用什么命令来编译代码?另外,您是否考虑过升级到 Angular 9 或 10?
-
命令:
ng build --configuration=dev --aot。我暂时不能升级 -
那么我们需要 angular.json
-
在某些时候,cli 开始要求在 tsconfig 中包含所有候选环境替换(或 angular.json 无法记住),以使其正常工作。仅在 env 目录中有 environment.xxx.ts 是不够的。
-
@Antoniossss 我可以确认情况并非如此。至少不适用于 Angular 9...
标签: angular typescript npm angular8 angular-cli-v8