Using invalid environment causes error in build (was "ERROR in Cannot read property 'length' of undefined")
(on existing project, on windows10) After updating :
- cli 31 to rc0
- angular packages to rc1
- typescript to 2.1.6
I get this insignifiant message error when running ng serve or ng build:
Cannot read property 'length' of undefined TypeError: Cannot read property 'length' of undefined
What does this mean ?
I have the exact same problem as @FunnyGhost (angular-cli 1.7.0, angular 2.4.10 typescript 2.2.2). Downgrading the angular-cli to 1.6.1 resolved my problem, but version 1.6.1 required angular-devkit/core in devDependencties
I too like others found the problem to be with the "plugin.js" file within "node_modules@ngtools\webpack\src\plugin.js". The problem is with the "_findLazyRoutesInAst()" function. This function is called on the second pass when running your unit test (w/ Karma). This function only looks at files that have been modified, and there is a file path in the array "this._compilerHost.getChangedFilePaths()" that ends with "/src", and all of the other paths end with .ts files. To resolve this problem, I check the file path to see if it ends with ".ts", and if so, I push that path into an array. Below is my solution to this problem. I would like to submit this as a bug fix, but I do not know where to do so.
------- plugin.js : ln 211 -------
_findLazyRoutesInAst() { benchmark_1.time('AotPlugin._findLazyRoutesInAst'); const result = Object.create(null); var changedFilePaths = []; this._compilerHost.getChangedFilePaths().forEach(f => { if(f.endsWith(".ts")) { changedFilePaths.push(f); } }); for (const filePath of changedFilePaths) { const fileLazyRoutes = lazy_routes_1.findLazyRoutes(filePath, this._compilerHost, this._program);
I have modified this file and it works fine, but it will never be fixed in any new version? This is my solution, it's similar to @ atariman5000 but inside an for:
_findLazyRoutesInAst() {
benchmark_1.time('AotPlugin._findLazyRoutesInAst');`
const result = Object.create(null);`
const changedFilePaths = this._compilerHost.getChangedFilePaths();`
for (const filePath of changedFilePaths) {
>> if(filePath.match(/.*\/*\.[A-Za-z]*$/)) {
const fileLazyRoutes = lazy_routes_1.findLazyRoutes(filePath, this._compilerHost, this._program);
for (const routeKey of Object.keys(fileLazyRoutes)) {
const route = fileLazyRoutes[routeKey];
if (routeKey in this._lazyRoutes) {
if (route === null) {
this._lazyRoutes[routeKey] = null;
}
else if (this._lazyRoutes[routeKey] !== route) {
this._compilation.warnings.push(new Error(`Duplicated path in loadChildren detected during a rebuild. `
+ `We will take the latest version detected and override it to save rebuild time. `
+ `You should perform a full build to validate that your routes don't overlap.`));
}
}
else {
result[routeKey] = route;
}
}
}
}
benchmark_1.timeEnd('AotPlugin._findLazyRoutesInAst');
return result;
}
I had a similar message recently when I added some new environments files in the angular-cli.json
"prod": "environments/environment.prod.ts",
"xamp": "environments/environment.xamp..ts"
The problem was I misstyped the name of one of the files: environment.xamp**.**.ts (I typed twice the dot)
I was very hard to figure what was wrong with my project (I knew only it had to be something with the environments files). A nice error sugesting about how i misspelled the files would have been perfect :/
This error should be improved.. for instance.. in most of the cases is the environment.xxx.ts missing.. so a message where file could not be found would be nice!
My team has been struggling with this for months, but @mhamel06's comment resolved the issue for me. It would be nice to have an actual fix that doesn't require modification of a lib file though.
The variant of the problem described by @FunnyGhost in https://github.com/angular/angular-cli/issues/5053#issuecomment-355977860 is gone in 6.0.7.
The above comment about the environment file caught my attention. I was with the same problem and looking at my .angular-cli.json I could fix and reproduce the error when one of those files below were missing:
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts",
"qa": "environments/environment.qa.ts"
}
So, those files must exist otherwise this error will happen. The cli could raise a more meaningful error message.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.