Angular 2 CLI环境设置

时间:2017-09-11 11:09:31

标签: angular environment

我想为Angular 2项目设置开发,测试(QA)和PROD环境。 在进行QA环境设置ng build --environment=qa

我收到以下错误

  

无法读取未定义的属性“长度”       at createSourceFile(D:\ ECC Web \ ECC WEB \ working \ 8-Aug \ node_modules \ typescript \ lib \ typescript.js:15457:109)       at parseSourceFileWorker(D:\ ECC Web \ ECC WEB \ working \ 8-Aug \ node_modules \ typescript \ lib \ typescript.js:15389:26)       at Object.parseSourceFile(D:\ ECC Web \ ECC WEB \ working \ 8-Aug \ node_modules \ typescript \ lib \ typescript.js:15338:26)       at 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)       at findSourceFile(D:\ ECC Web \ ECC WEB \ working \ 8-Aug \ node_modules \ typescript \ lib \ typescript.js:67909:29)       at processImportedModules(D:\ ECC Web \ ECC WEB \ working \ 8-Aug \ node_modules \ typescript \ lib \ typescript.js:68056:25)       at findSourceFile(D:\ ECC Web \ ECC WEB \ working \ 8-Aug \ node_modules \ typescript \ lib \ typescript.js:67937:17)       at processSourceFile(D:\ ECC Web \ ECC WEB \ working \ 8-Aug \ node_modules \ typescript \ lib \ typescript.js:67840:27)       at 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       at Object.forEach(D:\ ECC Web \ ECC WEB \ working \ 8-Aug \ node_modules \ typescript \ lib \ typescript.js:1449:30)       at 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
  };

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

看起来,我们在 environment / environment.qa.ts

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

您可以尝试参考此文档angular-cli-using-the-environment-option