Cannot read property 'bindingStartIndex' of null when using Library
See original GitHub issue🐞 bug report
Affected Package
Not sure. Maybe this is somewhere in @angular/cli or somewhere related to Webpack.
Is this a regression?
Yes, the previous version in which this bug was not present was Angular 8
Description
When creating a library as described in the documentation and using it in an empty app, I get the following error at runtime:
ERROR TypeError: Cannot read property 'bindingStartIndex' of null
at Module.ɵɵelementStart (core.js:20997)
at MyLibComponent_Template (my-lib.js:19)
at executeTemplate (core.js:11930)
at renderView (core.js:11716)
at renderComponent (core.js:13232)
at renderChildComponents (core.js:11519)
at renderView (core.js:11742)
at renderComponent (core.js:13232)
at renderChildComponents (core.js:11519)
at renderView (core.js:11742)
I do not see any errors while compiling.
🔬 Minimal Reproduction
I did the following:
- Create a
my-libsproject:ng new my-libs --create-application=false - Create a library:
cd my-libsandng generate library my-lib - Create an app next to this:
cd ..andng new my-app - Add the library as a dependency of the app: Add
"my-lib": "file:../my-libs/dist/my-lib"to thedependenciesin the app’spackage.jsonand runnpm install - Import the
MyLibModulein theAppModule(imported viaimport { MyLibModule } from 'my-lib';) - Use the component in the
AppComponent:<lib-my-lib></lib-my-lib> - Build the library:
cd my-libsandng build --prod - Run the app:
cd ..andng serve - Point browser at
http://localhost:4200/ - Open Developer Tools to look at the console
The resulting project is contained in this zip-file repro.zip. I removed the node_modules, so please do
$ cd my-libs
$ npm install
$ ng build --prod
$ cd ..
$ cd my-app
$ npm install
$ ng serve
🔥 Exception or Error
ERROR TypeError: Cannot read property 'bindingStartIndex' of null
at Module.ɵɵelementStart (core.js:20997)
at MyLibComponent_Template (my-lib.js:19)
at executeTemplate (core.js:11930)
at renderView (core.js:11716)
at renderComponent (core.js:13232)
at renderChildComponents (core.js:11519)
at renderView (core.js:11742)
at renderComponent (core.js:13232)
at renderChildComponents (core.js:11519)
at renderView (core.js:11742)
🌍 Your Environment
Angular Version:
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 9.0.2
Node: 12.13.0
OS: darwin x64
Angular:
...
Ivy Workspace:
Package Version
------------------------------------------------------
@angular-devkit/architect 0.900.2
@angular-devkit/core 9.0.2
@angular-devkit/schematics 9.0.2
@schematics/angular 9.0.2
@schematics/update 0.900.2
rxjs 6.5.3
Issue Analytics
- State:
- Created 4 years ago
- Reactions:26
- Comments:22 (2 by maintainers)
Top Results From Across the Web
Angular 10 Cannot read property 'bindingStartIndex' of null ...
Using components from my App or injecting Services from my Library are working fine. Test.component import { Component, OnInit } from '@angular/ ...
Read more >Angular: How to Deal With That Pesky 'Cannot Read Property ...
But lo and behold, when you try to display the contents of a component, you get this error: "Cannot read property 'bindingStartIndex' of...
Read more >Angular component in locale usage | by Marek Vondra - Medium
For the rest of us, we create the library project with the ... ERROR TypeError: Cannot read properties of null (reading 'bindingStartIndex').
Read more >Angular 10 + Storybook + npm package = NG Design System
Using the library package through local binding". ... ERROR TypeError: Cannot read properties of null (reading 'bindingStartIndex')
Read more >Angualr-Library笔记_@带甜味的盐@的博客
创建library; library本地测试; watch实时监听library 变化. 常见错误. TypeError: Cannot read property 'bindingStartIndex' of null. 发布到NPM.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
in your angular app that depends on your local library, set
projects.projectName.architect.build.options.preserveSymlinkswithtrueinangular.jsonwill prevent the angular cli from updating linked local libraryThis happens when
@NgModule()is resolved from a differentnode_moduleslocation.Given this configuration, we can use
my-libfrommy-appdirectly without buildingmy-lib:As @mhevery highlighted, the error indicates that somehow there are two copies of Ivy in there. This was due to TypeScript’s module resolution approach - it looks for
node_modulesby traversing up the directory of file being compiled.To fix this, I tell Typescript where to find Angular packages by using:
Initial test seems to be working. Hope this helps.
Also, I think this approach does not depend on
preserveSymlinksor"enableIvy": false.