angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Using invalid environment causes error in build (was "ERROR in Cannot read property 'length' of undefined")

Open elvisbegovic opened this issue 9 years ago • 169 comments

(on existing project, on windows10) After updating :

  1. cli 31 to rc0
  2. angular packages to rc1
  3. 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 ?

elvisbegovic avatar Feb 27 '17 12:02 elvisbegovic

@istiti can you fill out the issue template and give the steps to reproduce? What version of the cli are you updating from?

deebloo avatar Feb 27 '17 12:02 deebloo

@deebloo please apologize see point 1 again. I have no additional info:


Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at createSourceFile (C:\Users\.....\node_modules\typescript\lib\typescript.js:14552:109)
    at parseSourceFileWorker (C:\Users\.....\node_modules\typescript\lib\typescript.js:14484:26)
    at Object.parseSourceFile (C:\Users\.....\node_modules\typescript\lib\typescript.js:14433:26)
    at Object.createSourceFile (C:\Users\.....\node_modules\typescript\lib\typescript.js:14288:29)
    at WebpackCompilerHost.getSourceFile (C:\Users\.....\node_modules\@ngtools\webpack\src\compiler_host.js:210:27)
    at findSourceFile (C:\Users\.....\node_modules\typescript\lib\typescript.js:63453:29)
    at processSourceFile (C:\Users\.....\node_modules\typescript\lib\typescript.js:63384:27)
    at C:\Users\.....\node_modules\typescript\lib\typescript.js:63494:17
    at Object.forEach (C:\Users\.....\node_modules\typescript\lib\typescript.js:1293:30)
    at processReferencedFiles (C:\Users\.....\node_modules\typescript\lib\typescript.js:63492:16)
    at findSourceFile (C:\Users\.....\node_modules\typescript\lib\typescript.js:63477:21)
    at processImportedModules (C:\Users\.....\node_modules\typescript\lib\typescript.js:63600:25)
    at findSourceFile (C:\Users\.....\node_modules\typescript\lib\typescript.js:63481:17)
    at processSourceFile (C:\Users\.....\node_modules\typescript\lib\typescript.js:63384:27)
    at processRootFile (C:\Users\.....\node_modules\typescript\lib\typescript.js:63271:13)
    at C:\Users\.....\node_modules\typescript\lib\typescript.js:62620:60
    at Object.forEach (C:\Users\.....\node_modules\typescript\lib\typescript.js:1293:30)
    at Object.createProgram (C:\Users\.....\node_modules\typescript\lib\typescript.js:62620:16)
    at AotPlugin._setupOptions (C:\Users\.....\node_modules\@ngtools\webpack\src\plugin.js:124:28)
    at new AotPlugin (C:\Users\.....\node_modules\@ngtools\webpack\src\plugin.js:23:14)
    at _createAotPlugin (C:\Users\.....\node_modules\@angular\cli\models\webpack-configs\typescript.js:55:12)
    at Object.exports.getNonAotConfig (C:\Users\.....\node_modules\@angular\cli\models\webpack-configs\typescript.js:70:19)
    at NgCliWebpackConfig.buildConfig (C:\Users\.....\node_modules\@angular\cli\models\webpack-config.js:27:37)
    at Class.run (C:\Users\.....\node_modules\@angular\cli\tasks\serve.js:37:98)
    at check_port_1.checkPort.then.port (C:\Users\.....\node_modules\@angular\cli\commands\serve.js:103:26)
    at process._tickCallback (internal/process/next_tick.js:103:7)

elvisbegovic avatar Feb 27 '17 12:02 elvisbegovic

@istiti Did you use ng new to create the project?

If so, make sure that you kept all original arrays in .angular-cli.json configuration like assets, styles and scripts. I received mistake as you do, because I removed assets option from .angular-cli.json.

dmytro-y-dev avatar Feb 27 '17 13:02 dmytro-y-dev

@metamaker no I don't use ng new I have assets styles and scripts as array. I try on exisiting project running angular 2.4.8 ith cli31 to update to cli-rc0 and angular rc1 !

elvisbegovic avatar Feb 27 '17 13:02 elvisbegovic

Provide your .angular-cli.json, please.

dmytro-y-dev avatar Feb 27 '17 13:02 dmytro-y-dev

https://gist.github.com/istiti/e544744f16480829416e62b32167051e

ps: when running ng new test --ng4 it works... but I want get working again my existing project

elvisbegovic avatar Feb 27 '17 13:02 elvisbegovic

Your .angular-cli.json looks ok, not sure what is wrong. Maybe someone else will be able to help you ;) .

dmytro-y-dev avatar Feb 27 '17 13:02 dmytro-y-dev

additional info : I tried in green project "ng new mynewproject --ng4" it work well, it run!

then move all my old /app folder to this new one and I get same error !

apparently the issue is in my code/module ... My project is relativly big I can't remove module by module :(

how achieve this ? can I get more signifiant message error

thanks

elvisbegovic avatar Feb 27 '17 14:02 elvisbegovic

This is a real issue and we will look at it.

hansl avatar Feb 27 '17 18:02 hansl

Additionals infos: Yes of course I always use Renderer and template in my project.. but need more signifiant message error to achieve this properlly.

Thanks, actually can't move...

Cc @hansl

elvisbegovic avatar Feb 27 '17 18:02 elvisbegovic

@isiti can you provide a repository or some sort of code sample that we could use to reproduce? Maybe your package.json might be enough, if you're okay to share that.

hansl avatar Feb 28 '17 20:02 hansl

Will do it tomorrow at 7AM (UTC +1)

Thanks coz can't move (actually blocked)

@Hansl

elvisbegovic avatar Feb 28 '17 20:02 elvisbegovic

I was experiencing the same issue here and after I rolled typescript back from 2.2.1 to 2.0.10 that seemed to fix it.

trentmswanson avatar Feb 28 '17 21:02 trentmswanson

@hansl here you are https://gist.github.com/istiti/f97eb83c6d18fd1d23965e4a3325033e

@trentmswanson FYI after passing from 2.1.6 to 2.0.10 I get this error

then when I update typescript from 2.0.10 to 2.2.1 I get same error as in 2.1.6

elvisbegovic avatar Mar 01 '17 07:03 elvisbegovic

The strange thing here: the project with angular-cli rc.0 was working fine till executing the first ng build --target=production (maybe just a coincidence). Since then the project is broken. ng serve gives the same error now.

When I setup a new project, it is possible to build.

I removed and reinstalled angular-cli like documented (including node_modules) - the same. Also downgraded Typescript to 2.0.0 like the default for a blank project and took all possible settings of a blank project.

rdesimone avatar Mar 01 '17 11:03 rdesimone

Checking out from the repository into a new directory and running npm install fixed the issue - the files are the same. The project in the original directory became suddenly unusable - was not able to find out the reason.

rdesimone avatar Mar 01 '17 15:03 rdesimone

As said : I putt in new green cli --ng4 project whole my /app folder and same issue

elvisbegovic avatar Mar 01 '17 15:03 elvisbegovic

Apart from the lack of a descriptive message (which is the main focus for this issue), should anyone run into this case, don't panic - chances are that it's just a temporary glitch. I ran into this situation twice and it looked like a local problem with syncing files. The second incident of mine was a bit more clear to me - it followed a git pull. Waiting ca 1 minute and rebooting ng serve cured the app and restored its running state.

FWIW: Since this is ng serve reboot that helps, I would recommend to look closer at the angular-cli.json file - perhaps into the apps.assets item which has been made a mandatory array if I am correct (meaning it does not accept a single string anymore).

moniuch avatar Mar 01 '17 16:03 moniuch

additional info: same behavior with angular rc2

elvisbegovic avatar Mar 02 '17 07:03 elvisbegovic

additional info

with this conf. my project works/compile fine with typescript 2.1.6 here's my working package.json:

@angular/cli: 1.0.0-rc.0
node: 6.9.2
os: win32 x64
@angular/common: 2.4.9
@angular/compiler: 2.4.9
@angular/core: 2.4.9
@angular/forms: 2.4.9
@angular/http: 2.4.9
@angular/platform-browser: 2.4.9
@angular/platform-browser-dynamic: 2.4.9
@angular/router: 3.4.9
@angular/cli: 1.0.0-rc.0
@angular/compiler-cli: 2.4.9

BUT it breaks

when I add these lines to my package.json, I get length undefined:

"@angular/common": ">=4.0.0-beta <5.0.0",
"@angular/compiler": ">=4.0.0-beta <5.0.0",
"@angular/core": ">=4.0.0-beta <5.0.0",
"@angular/forms": ">=4.0.0-beta <5.0.0",
"@angular/http": ">=4.0.0-beta <5.0.0",
"@angular/platform-browser": ">=4.0.0-beta <5.0.0",
"@angular/platform-browser-dynamic": ">=4.0.0-beta <5.0.0",
"@angular/router": ">=4.0.0-beta <5.0.0"

elvisbegovic avatar Mar 02 '17 10:03 elvisbegovic