angular-cli: Lazy loading module broken with " No module factory available for dependency type: ContextElementDependency"
Bug Report or Feature Request (mark with an x
)
- [x] bug report -> please search issues before submitting
- [ ] feature request
Versions.
$ ng --version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
@angular/cli: 1.1.0-rc.0
node: 6.10.0
os: win32 x64
@angular/common: 4.1.3
@angular/compiler: 4.1.3
@angular/core: 4.1.3
@angular/forms: 4.1.3
@angular/http: 4.1.3
@angular/platform-browser: 4.1.3
@angular/platform-browser-dynamic: 4.1.3
@angular/router: 4.1.3
@angular/cli: 1.1.0-rc.0
@angular/compiler-cli: 4.1.3
@angular/tsc-wrapped: 4.1.3
Repro steps.
Include a lazy loaded module in AppRoutingModule
.
This doesn’t happen with a fresh ng new <project>
set-up. When adding "webpack": "^2.5.0"
dependency, this breaks the build.
"typescript": "~2.3.1",
"webpack": "^2.5.0",
"webpack-dev-middleware": "^1.10.2",
"webpack-dev-server": "^2.4.5",
"webpack-md5-hash": "^0.0.5",
"webpack-merge": "^4.1.0"
A repro can be found here: dherges/ng-cli-lazy-loading-broken-6417. The change in package.json dependencies breaks the build.
The log given by the failure.
webpack: Compiling...
40% building modules 1/2 modules 1 active ...ework\guide\app\app-routing.module.tsError: No module factory available for dependency type: ContextElementDependency
at Compilation.addModuleDependencies (<project>\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:206:21)
at Compilation.processModuleDependencies (<project>\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:195:8)
at _this.buildModule.err (<project>\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:336:13)
at building.forEach.cb (<project>\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:140:27)
at Array.forEach (native)
at callback (<project>\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:140:13)
at module.build (<project>\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:167:11)
at resolveDependencies (<project>\node_modules\@angular\cli\node_modules\webpack\lib\ContextModule.js:133:4)
at ContextModule.result.resolveDependencies (<project>\node_modules\@ngtools\webpack\src\plugin.js:229:25)
at ContextModule.build (<project>\node_modules\@angular\cli\node_modules\webpack\lib\ContextModule.js:103:8)
at Compilation.buildModule (<project>\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:142:10)
at factoryCallback (<project>\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:325:11)
at <project>\node_modules\@angular\cli\node_modules\webpack\lib\ContextModuleFactory.js:96:12
at <project>\node_modules\tapable\lib\Tapable.js:204:11
at done.then (<project>\node_modules\@ngtools\webpack\src\plugin.js:231:28)
at process._tickCallback (internal/process/next_tick.js:103:7)
70% building modules 2/2 modules 0 active
14% building modules 36/48 modules 12 active ...e_modules\rxjs\add\operator\filter.js<project>\node_modules\@angular\cli\node_modules\webpack\li
b\Compilation.js:265
if(_this.profile) {
^
TypeError: Cannot read property 'profile' of null
at factoryCallback (<project>\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:265:13)
at factory (<project>\node_modules\@angular\cli\node_modules\webpack\lib\NormalModuleFactory.js:253:5)
at applyPluginsAsyncWaterfall (<project>\node_modules\@angular\cli\node_modules\webpack\lib\NormalModuleFactory.js:99:14)
at <project>\node_modules\tapable\lib\Tapable.js:204:11
at NormalModuleFactory.params.normalModuleFactory.plugin (<project>\node_modules\@angular\cli\node_modules\webpack\lib\CompatibilityPlugin.js
:52:5)
at NormalModuleFactory.applyPluginsAsyncWaterfall (<project>\node_modules\tapable\lib\Tapable.js:208:13)
at resolver (<project>\node_modules\@angular\cli\node_modules\webpack\lib\NormalModuleFactory.js:74:11)
at process.nextTick (<project>\node_modules\@angular\cli\node_modules\webpack\lib\NormalModuleFactory.js:205:8)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
Desired functionality.
Lazy loading:
const routes: Routes = [
{
path: 'content',
loadChildren: './+content/content.module#ContentModule'
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
Mention any other details that might be useful.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 25
- Comments: 58 (7 by maintainers)
Commits related to this issue
- fix(@ngtools/webpack): prevent ContextElementDependency errors This should allow multiple webpack versions in the workspace dependencies with no weird errors. Fix https://github.com/angular/angular-... — committed to filipesilva/angular-cli by filipesilva 6 years ago
- feat(@ngtools/webpack): allow passing in the right ContextElementDependency class This should allow multiple webpack versions in the workspace dependencies with no weird errors. Fix https://github.c... — committed to filipesilva/angular-cli by filipesilva 6 years ago
- feat(@ngtools/webpack): allow passing in the right ContextElementDependency class This should allow multiple webpack versions in the workspace dependencies with no weird errors. Fix https://github.c... — committed to filipesilva/angular-cli by filipesilva 6 years ago
- feat(@ngtools/webpack): allow passing in the right ContextElementDependency class This should allow multiple webpack versions in the workspace dependencies with no weird errors. Fix https://github.c... — committed to filipesilva/angular-cli by filipesilva 6 years ago
- feat(@ngtools/webpack): allow passing in the right ContextElementDependency class This should allow multiple webpack versions in the workspace dependencies with no weird errors. Fix https://github.c... — committed to filipesilva/angular-cli by filipesilva 6 years ago
- feat(@ngtools/webpack): allow passing in the right ContextElementDependency class This should allow multiple webpack versions in the workspace dependencies with no weird errors. Fix https://github.c... — committed to filipesilva/angular-cli by filipesilva 6 years ago
- feat(@ngtools/webpack): allow passing in the right ContextElementDependency class This should allow multiple webpack versions in the workspace dependencies with no weird errors. Fix https://github.c... — committed to filipesilva/angular-cli by filipesilva 6 years ago
- feat(@ngtools/webpack): allow passing in the right ContextElementDependency class This should allow multiple webpack versions in the workspace dependencies with no weird errors. Fix https://github.c... — committed to filipesilva/angular-cli by filipesilva 6 years ago
- feat(@ngtools/webpack): allow passing in the right ContextElementDependency class This should allow multiple webpack versions in the workspace dependencies with no weird errors. Fix https://github.c... — committed to filipesilva/angular-cli by filipesilva 6 years ago
- feat(@ngtools/webpack): allow passing in the right ContextElementDependency class This should allow multiple webpack versions in the workspace dependencies with no weird errors. Fix https://github.c... — committed to angular/angular-cli by filipesilva 6 years ago
- feat(@ngtools/webpack): allow passing in the right ContextElementDependency class This should allow multiple webpack versions in the workspace dependencies with no weird errors. Fix https://github.c... — committed to filipesilva/angular-cli by filipesilva 6 years ago
- feat(@ngtools/webpack): allow passing in the right ContextElementDependency class This should allow multiple webpack versions in the workspace dependencies with no weird errors. Fix https://github.c... — committed to filipesilva/angular-cli by filipesilva 6 years ago
- Fixed prod build issue - Updated packages where possible (fixing the prod build) - Added workaround to gulpfile for webpack reference, see https://github.com/angular/angular-cli/issues/6417 — committed to MattJeanes/Ombi by MattJeanes 6 years ago
- feat(@ngtools/webpack): allow passing in the right ContextElementDependency class This should allow multiple webpack versions in the workspace dependencies with no weird errors. Fix https://github.c... — committed to ikjelle/angular-cli by filipesilva 6 years ago
fixed :
npm uninstall --save-dev webpack
sudo rm -R node_modules
npm install
i think its not lazy load problem also i got this only after implementing the universalI did get this working
I deleted my package lock file delete node_modules remove any reference to webpack from my package.json npm install
Closing as this seems to be caused by trying to install a different version of
webpack
than the one that@angular/cli
depends on. This is not supported. Please ensure you only have@angular/cli
inpackage.json
, and notwebpack
. You can check if you have multiple versions of webpack by doingnpm ls webpack
.If removing webpack from your package.json doesn’t work for you:
In my case I just needed to update the following dependencies : “@angular-devkit/core”, “@angular-devkit/build-angular”, and “@angular-devkit/schematics” to the following version : “0.8.1”.
This way “@angular-devkit/build-angular” had the same version than the webpack specified in my package.json (4.18.0).
This means that if your run
npm ls webpack
and have multiple results, you don’t have to remove webpack from your project, you just need both versions to be the same.Seems like this issue came back again
/ \ _ __ __ _ _ | | __ _ _ __ / | | | | / △ \ | ’ \ / _
| | | | |/ _
| '| | | | | | | / ___ | | | | (| | || | | (| | | | || | | | // __| ||_, |_,||_,|| _||| |___/ @angular/cli: 1.4.4 node: 8.2.1 os: darwin x64 @angular/animations: 4.4.4 @angular/common: 4.4.4 @angular/compiler: 4.4.4 @angular/core: 4.4.4 @angular/forms: 4.4.4 @angular/http: 4.4.4 @angular/platform-browser: 4.4.4 @angular/platform-browser-dynamic: 4.4.4 @angular/router: 4.4.4 @angular/cli: 1.4.4 @angular/compiler-cli: 4.4.4 @angular/language-service: 4.4.4Error: No module factory available for dependency type: ContextElementDependency
@rudzikdawid I checked your example and it definitely has two versions of webpack installed:
Refer back to my earlier comment (https://github.com/angular/angular-cli/issues/6417#issuecomment-315708400) about how this is not supported.
@dzolnjan if it works in one environment and not another, it’s usually because your dependency set is differente. Maybe cache, maybe yarn.lock, maybe package-lock.json.
Just upgraded to latest Angular 6.1 and angular-cli 6.1.1 and I get this error
The most likely cause is a webpack version mismatch. Version 1.1 of the CLI uses 2.4.x.
@peterpeterparker, after fighting with this for hours, I tried your solution and it worked. I think the only difference with the others was
rm package-lock.json
Thanks!!! 😃My solution is
npm un --save-dev @ngtools/webpack
then add"@ngtools/webpack" : "^6.0.8",¬
to package.json I think it’s conflict on version on dev-packageEventually I figured it out, but it’s been 11 days ago, @victorjatoba here is my current package.json
I’m sure there are packages here you don’t use, but this is the combination that I’m working with and it builds fine
When I run ng version I get this:
I just ran into this while upgrading angular-cli to latest version:
I read the post about multiple versions of webpack but removing webpack from package.json gives “Cannot find module ‘webpack’” . Running npm ls webpack lists no webpack versions, not even under @angular-devkit. If I then install webpack , npm ls webpack lists two versions:
on doing ng build I get the following … it’s catch 22
finally I manually installed webpack@4.9.2 as specified by @angular-devkit/build-angular~0.7.1 , and then ng serve can run, but the first problem persists
As am I. I have confirmed that we only have a single Webpack version in our NPM and it is the one coming in with the Angular CLI.
Currently unable to do module lazy loading due to this issue.
webpack: 3.5.6 @angular/cli: 1.4.3 node: 8.1.0 @angular/core: 4.4.4 typescript: 2.3.0
@alexfung888 The team just recently added a new command flag that I find very welcome. What I do is add the flag in my
package.json
file like so:So for example - I currently have v1.2.0-beta.0 of the CLI installed globally. Then I git clone master and do an
npm link
of course like the documentation says then Inpm link @angular/cli
within my Angular project. Run npm start and most of the time you are good to go!