1

I have an Angular 5 app that was previously running on Angular CLI 1.2.8 and everything was working great. After the upgrade to 1.3 (on my way to 1.5.4) there seems to be an issue with the external npm link libary we are using as I get an NullInjectorError: No provider for Http! when visiting localhost:4200

When I add the HttpModule to the shared-lib module, the error goes away but I get additional provider errors. I am expecting the shared-lib to use the modules from the main app as it did before, not the shared-lib module. In this example the shared-lib has angular services that rely on HttpModule but the shard-lib does not import HttpModule. The main project I am using does import HttpModule.

My tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "types": [ "node", "jasmine" ],
    "lib": [
      "es2016",
      "dom"
    ],
    "paths": {
      "rxjs/*": [
        "node_modules/rxjs/*"
      ],
      "@angular/*": [
        "node_modules/@angular/*"
      ]
    }
  }
}

my tsconfig.app.json:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "baseUrl": "",
    "types": []
  },
  "include": [
    "./**/*.ts",
    "../node_modules/shared-lib/src/**/*.ts",
    "../node_modules/shared-lib/index.ts",
    "../node_modules/shared-lib/shared-lib.ts"
  ],
  "exclude": [
    "test.ts",
    "**/*.spec.ts",
    "../node_modules/shared-lib/**/*.spec.ts"
  ],
  "typeRoots": [
    "node_modules/@types"
  ],
  "types": [ "node" ]
}

Update: I have found that after deleting the @angular folder in the shared-lib node_modules, the project works. I am not sure why they paths object in the tsconfig.json is not overriding the use of Angular to my project's node_modules only.

that_guy
  • 2,313
  • 4
  • 33
  • 46

2 Answers2

0

I faced a similar problem with angular/cli version not compatible with the current node version. The problem lies in upgrading the dependencies. This generally happens when you are upgrading from lower version of Angular to any other higher version. You can try following steps:

npm outdated  --> To list latest and current package details in local application.
npm update    --> to update the local packages.

If it still doesn`t work, Try deleting the 'node_modules' folder and install dependencies of fresh:

npm install

You can then check whether all packages, including the cli is not outdated.

Rahul
  • 121
  • 1
  • 2
  • 10
  • Also you might need to update your package.json. This can be done by executing following command 'ncu -u' – Rahul Nov 29 '17 at 20:59
  • All angular packages are up to date, I am using node 6.11.2 which is higher than the required 6.9.0 – that_guy Nov 30 '17 at 12:43
0

Could it be some sort of conflict because of the deprecated HttpModule? For the more recent versions you should be using the HttpClientModule as the HttpModule was deprecated.

Hugo Noro
  • 3,145
  • 2
  • 13
  • 19
  • I don't believe so, I can make the error go away if I include HttpModule in the linked library's imports but I get another import error. I am expecting it to be taking to HttpModule import from the main project and not the linked project. I have another project that uses the linked library just fine however it is setup without the CLI. – that_guy Nov 30 '17 at 12:30