1
votes

I want to set up development, test(QA) and PROD environment for my Angular 2 project. While going for QA env set up ng build --environment=qa

I am getting below error

Cannot read property 'length' of undefined 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) at VirtualFileStats.getSourceFile (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\@ngtools\webpack\src\compiler_host.js:66:35) at 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) at 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) at AotPlugin._setupOptions (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\@ngtools\webpack\src\plugin.js:129:28) at new AotPlugin (D:\ECC Web\ECC WEB\working\8-Aug\node_modules\@ngtools\webpack\src\plugin.js:26:14)

Below is my code for environment set up in angular-cli.json

"environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts",
        "qa": "environments/environment.qa.ts"
      }

in environments/environment.qa.ts

export const environment = {
    production: false
  };
2
Do you have the same variables in your other environment.ts files? Also, are you certain the file name in your angular-cli.json matches the actual file name?EvanM
As @EvanM suggested, check the names of your environment.*.ts files and the config under environments in .angular-cli.json. In my case, it was just a typo: envrionment.qa.ts instead of environment.qa.ts.San

2 Answers

2
votes

Typescript probably wants to read a source file that doesn't exist. The stack trace doesn't mention the name of the missing file, but you can get it by editing the file node_modules\typescript\lib\typescript.js - add a log statement console.log(fileName); at the beginning of the createSourceFile method and run the build command again. The last filename before the error should be the one causing the problem.

0
votes

It seems like that,we set envName in environments/environment.qa.ts

export const environment = {  
        production: false,
        envName: 'qa'
 };

can you try this refer this doc angular-cli-using-the-environment-option