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've received this error when a generated (and referenced) d.ts file was missing. If you receive the error the issue is probably in you project..
/// <reference path="../../someFileThatDidntExist.d.ts" />
thank you for clarifications CanKattwinkel, The question is: Why earlier versions of @angular/cli does not happen ?
Why should i do, ignore in the exclude tag of tsconfig, some important dependency modules?
Some suggestion?
FWIW in my case this error tripped after a large refactor / rename exercise. It went away after I restarted ng serve.
I stopped ng serve and restarted it, now the error message is gone.
I also had issues with my build. The issue was with the environment files in my angular-cli.json as pointed by @moosetraveller and some others.
Thank you all for big help!
I had the same error. My problem was that the "test.ts" under the "src" folder was missing for some reason. Restored the file from a backup and it is working fine now. The karma.conf.js has a reference to that file as... { pattern: './src/test.ts', watched: false }
Thanks for everyone for pointing me in the right direction.
I noticed that in a project created (that does not get this error) with ng new (@angular/cli 1.0.6) that the angular-cli.json file was renamed to .angular-cli.json (hidden file).
I renamed the file in my upgrading project but did not help. I mention this because there must be something else that has changed that may be causing the issue.
Although, this does seem like a code incompatibility issue - probably some dependency that is out of sync. But it is not obvious. I brought versions in package.json to the same levels.
For what it's worth, I got this error when referencing a d.ts file via: ///<reference path="./foo.d.ts" /> with an invalid path, which I discovered using @klferreira's suggestion, on #5132:
Put a console.log(fileName) in your createSourceFile() function and it will show you exactly where is the problem. Mine was environment.ts that was missing.
This error seem to have different reasons and different solutions. In my case I had a reference ///
pointing to a file that did not exist.
This happened to me, somehow my 'typings' folder was missing, I just restored it and everything worked fine.
@leandrolanzieri Thanks for the suggestion. This was the problem for me. Was banging my head against the wall for a while.
I hit this error when I started trying to work on a clean machine and cloned our repo.
Currently we have an environment.prod.ts & an environment.ts file referenced in our .angular-cli.json, however, it's up to the dev to create a local environment.ts and it's configured to be gitignored.
I forgot to create a local environment.ts and banged my head against this error for 45mins until I remembered to create one.
Like most other people on this thread I would have appreciated a pretty error message telling me that (in my case) "An environment.ts file was specified in .angular-cli.json but could not be found at this 'specific-path'"
I had the same issue. In my case, it was a typo in the environment settings in angular-cli,json. Make sure it spelled correctly like this environments/environment.xyz.ts.
I had the same issue. In my case, I had to remove some sub-folders under the 'typings' folder, which I forgot to also remove from the index.d.ts file. Hope this helps someone.
Guys any update on this issue ?
I have some problem in a fwe moments ago...
I shell ng serve -e local
And i check my .angular-cli.json file and not found "local": "environments/environment.local.ts"
Before i check this, problem is solved
Try this x)
P.S. Sorry for my bad english
I just had the same issue, and got to resolve it by changing the path to the enviroments folder in my .angular-cli.json. From this:
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
To this:
"environmentSource": "src/environments/environment.ts",
"environments": {
"dev": "src/environments/environment.ts",
"prod": "src/environments/environment.prod.ts"
}
Be sure that you've the reference to the files right.
FYI - I also get this issue when referencing an invalid d.ts file. Confirmed on 1.3.0-rc.5 (which I am stuck on due to another bug)
select: function () {
var self = this;
self.$http.post("/purchase/rfq-table", {
"username": self.options,
}).then(function(res){
var data = res.body.result;
self.tabledata = [];
if(data.length > 0){
data.forEach(function(val) {
self.tabledata.push({
"data": [
val.name,
val.schedule_date,
],
"url": "/purchase/RQ/"+val.id,
});
});
console.log(self.tabledata);
}
//self.options =res.body.data;
},function(err){
alert(err);
});
},
Uncaught (in promise) TypeError: Cannot read property 'length' of undefined
i dont know the error please help me out this.
@unsama simply do:
if(data && data.length > 0)
@istiti thanks