ng-packagr: StaticInjectionError for service after migrating to Angular 5. // Solution: `--preserve-symlinks`

Type of Issue

Service package error after migrate to Angular 5

[x] Bug Report [ ] Feature Request


## Description

I have an Angular CLI generated project that just has only one service file my-test.service.ts

@Injectable()
export class MyTestService {
   ......
}

I publish it to NPM using ng-packagr. I can use the package in my other projects before migrating to Angular 5. After migration, I got error:
 
ERROR Error: StaticInjectorError[MyTestService]: 
  StaticInjectorError[MyTestService]: 
    NullInjectorError: No provider for MyTestService!
    at _NullInjector.get (core.js:923)
    at resolveToken (core.js:1211)
    at tryResolveToken (core.js:1153)
    at StaticInjector.get (core.js:1024)
    at resolveToken (core.js:1211)
    at tryResolveToken (core.js:1153)
    at StaticInjector.get (core.js:1024)
    at resolveNgModuleDep (core.js:10585)
    at NgModuleRef_.get (core.js:11806)
    at resolveDep (core.js:12302)

#### How To Reproduce



#### Expected Behaviour



#### Version Information

ng-packagr: v1.6.0 node: v8.x.y @angular: v5.0.0 rxjs: zone.js:


_please include any version information that might be relevant, e.g. other third-party libraries_

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (7 by maintainers)

Most upvoted comments

Why is this closed? It seems it is not fixed, or is it? I see neither a fix nor a clear explanation.

@dherges should this really be closed?

I had the same issue and I’ve spent a full day trying to fix it. Deleting the package-lock.json file made it work. Thanks @jcjolley for this!

Any progress on this? I have a lib working on an angular 5 project that’s been ejected from the angular/cli, but am still running into StaticINjectionError[Router] on a separate project that is using the angular/cli.

EDIT: After doing the following steps, the library started working in the Angular CLI consumer app

  1. Create a new project with the Angular CLI.
  2. Copy over all of the dependencies from its package.json to the package.json of your consumer app.
  3. Delete the node_modules folder and package-lock.json in your consumer app.
  4. npm install in your consumer app

Hi @cathy02 @oliveti

For Angular v5, please use the 2.0.0 release candidates! Make sure you have a typescript version that is supported by Angular, i.e. “~2.4.x” for angular v5. Should the error still exist, please provide a reproduction, e.g. a GitHub repo.

For Angular v4, please use the 1.x version as it has the peerDependency on TypeScript 2.3.x which is recommended/supporter for Angular 4.