ng-packagr: TypeError: Cannot read property 'length' of undefined

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

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (3 by maintainers)

Commits related to this issue

Most upvoted comments

@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

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.

To clarify the comment @udnisap:

in the latest umd it is node_modules/@angular/compiler/bundles/compiler.umd.js: 10463 replace this:

return new _Tokenizer(new ParseSourceFile(source, url), getTagDefinition, options).tokenize();

with this:

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

Many thanks @johnnyprogger and @udnisap!

in the latest umd it is node_modules/@angular/compiler/bundles/compiler.umd.js: 10463

Why is the suggestion from @mikegoodstadt not committed or fix in the actual code?

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.

This was extremly helpful. Thank you so much for figuring that out. You should create a pull request for that. This error log is a no-brainer. Why is this not included in the source code?