【问题标题】:Angular 2 CLI environment set upAngular 2 CLI 环境设置
【发布时间】: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.jsonenvironments 下的配置。就我而言,这只是一个错字:envrionment.qa.ts 而不是 environment.qa.ts

标签: angular environment


【解决方案1】:

Typescript 可能想要读取一个不存在的源文件。堆栈跟踪没有提及丢失文件的名称,但您可以通过编辑文件node_modules\typescript\lib\typescript.js 来获取它 - 在createSourceFile 方法的开头添加一条日志语句console.log(fileName); 并再次运行构建命令。错误之前的最后一个文件名应该是导致问题的文件名。

【讨论】:

  • 感谢环境文件。
  • @Akanksha,您可以考虑接受答案,以便其他人知道您已经解决了问题并且作者得到了一些分数。
【解决方案2】:

好像是这样,我们在environments/environment.qa.ts

中设置了envName
export const environment = {  
        production: false,
        envName: 'qa'
 };

你可以试试这个参考这个文档angular-cli-using-the-environment-option

【讨论】:

  • 谢谢罗伯特。我已经尝试过这个文档,但没有设置质量检查环境。
猜你喜欢
  • 1970-01-01
  • 2017-07-28
  • 2017-06-01
  • 1970-01-01
  • 2017-07-04
  • 2018-12-25
  • 1970-01-01
  • 1970-01-01
  • 2015-12-13
相关资源
最近更新 更多