question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'length' of undefined

See original GitHub issue

Type of Issue

[x] Bug Report
[ ] Feature Request

Description

A bug: please describe the error that you encountered Seems to be when using a component with a templateUrl in 4.0.0 rc2 it always returns this error. Note my component is in a sub package within a regular angular cli project’s generated library.

A feature: please describe your use case and motivation

How To Reproduce

A bug: please include instructions how to reproduce. Issues without reproduction are likely to receive no feedback.

Can you reproduce the error in the integration tests in ng-packagr? If possible, take a look at the integration/samples and try to break one of these builds!

Is the error you faced in an application importing the library Try to break the Angular CLI app in integration/consumers/ng-cli!

Expected Behaviour

A bug: please describe what behaviour or result you expected

Components with template urls should compile.

A feature: do you have a first draft or an idea how to implement?

Error: : TypeError: Cannot read property 'length' of undefined
    at new _Tokenizer (/Users/ed/someproject/node_modules/@angular/compiler/bundles/compiler.umd.js:4535:38)
    at tokenize (/Users/ed/someproject/node_modules/@angular/compiler/bundles/compiler.umd.js:4493:12)
    at HtmlParser.Parser.parse (/Users/ed/someproject/node_modules/@angular/compiler/bundles/compiler.umd.js:5121:31)
    at HtmlParser.parse (/Users/ed/someproject/node_modules/@angular/compiler/bundles/compiler.umd.js:7768:39)
    at I18NHtmlParser.parse (/Users/ed/someproject/node_modules/@angular/compiler/bundles/compiler.umd.js:7957:44)
    at DirectiveNormalizer._preparseLoadedTemplate (/Users/ed/someproject/node_modules/@angular/compiler/bundles/compiler.umd.js:2035:51)
    at /Users/ed/someproject/node_modules/@angular/compiler/bundles/compiler.umd.js:2030:76
    at Object.then (/Users/ed/someproject/node_modules/@angular/compiler/bundles/compiler.umd.js:292:77)
    at DirectiveNormalizer._preParseTemplate (/Users/ed/someproject/node_modules/@angular/compiler/bundles/compiler.umd.js:2030:26)
    at DirectiveNormalizer.normalizeTemplate (/Users/ed/someproject/node_modules/@angular/compiler/bundles/compiler.umd.js:2015:36)

    at Object.<anonymous> (/Users/ed/someproject/node_modules/ng-packagr/lib/ngc/compile-source-files.js:53:68)
    at Generator.next (<anonymous>)
    at /Users/ed/someproject/node_modules/ng-packagr/lib/ngc/compile-source-files.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/ed/someproject/node_modules/ng-packagr/lib/ngc/compile-source-files.js:3:12)
    at Object.compileSourceFiles (/Users/ed/someproject/node_modules/ng-packagr/lib/ngc/compile-source-files.js:19:12)
    at Object.<anonymous> (/Users/ed/someproject/node_modules/ng-packagr/lib/ng-v5/entry-point/ts/compile-ngc.transform.js:28:32)
    at Generator.next (<anonymous>)
    at /Users/ed/someproject/node_modules/ng-packagr/lib/ng-v5/entry-point/ts/compile-ngc.transform.js:7:71
    at new Promise (<anonymous>)

Version Information

$ node_modules/.bin/ng-packagr --version
ng-packagr:            4.0.0-rc.2
@angular/compiler:     6.0.6
rollup:                0.60.7
tsickle:               0.30.0
typescript:            2.7.2

Please include all version numbers that might be relevant, e.g. third-party libraries

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

52reactions
rovicocommented, May 31, 2019

@johnnyprogger you saved my day! The error in my case was with incorrect template paths… Sometimes i think Angular ng build should be more verbose for such situations

36reactions
johnnyproggercommented, Sep 4, 2018

I ran into this with 1.6.2 RC0 and was able to debug it by adding a console log to the lexer.
In lexer.js, (line 77 as of writing), replace this:

return new _Tokenizer(new parse_util_1.ParseSourceFile(source, url), getTagDefinition, tokenizeExpansionForms, interpolationConfig).tokenize();

with this:

var parsedFile = new parse_util_1.ParseSourceFile(source, url);
if (parsedFile.content === undefined) {
    console.log("ERROR File not found: ", url);
}
return new _Tokenizer(parsedFile, getTagDefinition, tokenizeExpansionForms, interpolationConfig).tokenize();

This showed me the missing file and I was able to fix it within minutes. Hope this helps someone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read properties of undefined (reading 'length') - TrackJS
This message indicates that our code expects to have an object with a length property, but that object was not present. length is...
Read more >
TypeError: Cannot read property 'length' of Undefined in JS
The "Cannot read property 'length' of undefined" error occurs when accessing the length property on an undefined value. To solve the error, make...
Read more >
Typeerror: Cannot Read Property 'length' of Undefined
A typeerror length of undefined can indicate that the actual type of an operand is different from the expected type. This error can...
Read more >
[SOLVED] Cannot Read Property 'length' of Undefined in JS
To fix the “cannot read property 'length' of undefined” error, perform an undefined check on the variable before accessing the length property ......
Read more >
Cannot read property length of undefined - Stack Overflow
The error means that what ever element is returned by getElementById('WallSearch') , it does not have a value property. Every form field has...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found