【发布时间】:2018-02-19 14:40:26
【问题描述】:
我想为我的 Angular 2 项目设置开发、测试 (QA) 和 PROD 环境。
在进行 QA 环境设置时 ng build --environment=qa
我遇到了错误
无法读取未定义的属性“长度” 在 createSourceFile (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\typescript\lib\typescript.js:15457:109) 在 parseSourceFileWorker (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\typescript\lib\typescript.js:15389:26) 在 Object.parseSourceFile (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\typescript\lib\typescript.js:15338:26) 在 Object.createSourceFile (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\typescript\lib\typescript.js:15192:29) 在 VirtualFileStats.getSourceFile (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\@ngtools\webpack\src\compiler_host.js:66:35) 在 WebpackCompilerHost.getSourceFile (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\@ngtools\webpack\src\compiler_host.js:213:38) 在 findSourceFile (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\typescript\lib\typescript.js:67909:29) 在 processImportedModules (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\typescript\lib\typescript.js:68056:25) 在 findSourceFile (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\typescript\lib\typescript.js:67937:17) 在 processSourceFile (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\typescript\lib\typescript.js:67840:27) 在 processRootFile (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\typescript\lib\typescript.js:67728:13) 在 D:\ECC Web\ECC WEB\working\8-Aug\node_modules\typescript\lib\typescript.js:67018:60 在 Object.forEach (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\typescript\lib\typescript.js:1449:30) 在 Object.createProgram (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\typescript\lib\typescript.js:67018:16) 在 AotPlugin._setupOptions (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\@ngtools\webpack\src\plugin.js:129:28) 在新的 AotPlugin (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\@ngtools\webpack\src\plugin.js:26:14)
以下是我的环境设置代码 在 angular-cli.json 中
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts",
"qa": "environments/environment.qa.ts"
}
在环境/environment.qa.ts中
export const environment = {
production: false
};
【问题讨论】:
-
您的其他 environment.ts 文件中是否有相同的变量?另外,您确定 angular-cli.json 中的文件名与实际文件名匹配吗?
-
按照@EvanM 的建议,检查
environment.*.ts文件的名称以及.angular-cli.json中environments下的配置。就我而言,这只是一个错字:envrionment.qa.ts而不是environment.qa.ts。
标签: angular environment