1

If I want to make ng serve, I get this error :

ERROR in TypeError: Cannot read property 'provide' of undefined at C:\Users\Samir\Documents\AngularProjects\test\angular_website\node_modules\@angular\compiler-cli\src\ngtools_impl.js:150:14 at Array.reduce (native) at _collectRoutes (C:\Users\Samir\Documents\AngularProjects\test\angular_website\node_modules\@angular\compiler-cli\src\ngtools_impl.js:149:22) at _extractLazyRoutesFromStaticModule (C:\Users\Samir\Documents\AngularProjects\test\angular_website\node_modules\@angular\compiler-cli\src\ngtools_impl.js:113:8) at Object.listLazyRoutesOfModule (C:\Users\Samir\Documents\AngularProjects\test\angular_website\node_modules\@angular\compiler-cli\src\ngtools_impl.js:53:22) at Function.NgTools_InternalApi_NG_2.listLazyRoutes (C:\Users\Samir\Documents\AngularProjects\test\angular_website\node_modules\@angular\compiler-cli\src\ngtools_api.js:91:39) at AotPlugin._getLazyRoutesFromNgtools (C:\Users\Samir\Documents\AngularProjects\test\angular_website\node_modules\@ngtools\webpack\src\plugin.js:207:44) at _donePromise.Promise.resolve.then.then.then.then.then (C:\Users\Samir\Documents\AngularProjects\test\angular_website\node_modules\@ngtools\webpack\src\plugin.js:443:24)

I also deleted all node_modules and installed the newest version of the cli, but this is not my code. Has someone a solution for this problem ?

0

3 Answers 3

1

This error is usually comming from the import statement of a service. You should try importing the service using the exact path of the service itself instead of using an index.ts file that exports the service.

Instead of

Using index.ts file with:

export * from './services/myservice.service';

and then in the module/component that provides that service you are writing the import to the index.ts file like that:

import {MyService} from './services';

Try this

Try to import the service using the relative path to the service itself:

import {myService} from './services/myservice.service';
Sign up to request clarification or add additional context in comments.

4 Comments

are you sure? this are onyl ng_modules and it isn't code from me
This is the error that I got and what solved it for me. Do you have any services in your app?
if you have no code than I will recomand that you try upgrading yout angular-cli. Follow these instructions: github.com/angular/angular-cli#updating-angular-cli
This worked for me. I want to know why there is a difference between the 2 methods of importing. Logically they should be the same. This seems like a bug in angular.
0

In app.module.ts, are you using any import like this:

import MyImport from 'myPath';

? If yes, you need change your MyImport.ts to be imported like this:

import { MyImport } from 'myPath';

Comments

0

The issue is due to @Injectable(). Previous to Angular 11, @Injectable needs to be added for injecting services within a service.

In Angular 11 and future releases, @Injectable() needs to be added to all the defined services.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.