angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

build aot: Error: No module factory available for dependency type: ContextElementDependency

Open born2net opened this issue 9 years ago • 30 comments

OS?

angular-cli: 1.0.0-beta.26
node: 6.9.4
os: win32 x64
@angular/common: 2.4.5
@angular/compiler: 2.4.5
@angular/core: 2.4.5
@angular/forms: 2.4.5
@angular/http: 2.4.5
@angular/language-service: 2.4.5
@angular/platform-browser: 2.4.5
@angular/platform-browser-dynamic: 2.4.5
@angular/router: 3.2.1
@angular/compiler-cli: 2.4.5

Repro steps.

Repo: https://github.com/born2net/studioweb

The log given by the failure.

Trying to ng build aot

dump:

$ ng build --aot
 25% building modules 128/230 modules 102 active ...modules\@angular\core\src\metadata.js
An error occured during the build:
Error: No module factory available for dependency type: ContextElementDependency
    at Compilation.addModuleDependencies (C:\msweb\studioweb\node_modules\webpack\lib\Compilation.js:186:21)
    at Compilation.processModuleDependencies (C:\msweb\studioweb\node_modules\webpack\lib\Compilation.js:175:8)
    at _this.buildModule.err (C:\msweb\studioweb\node_modules\webpack\lib\Compilation.js:315:13)
    at building.forEach.cb (C:\msweb\studioweb\node_modules\webpack\lib\Compilation.js:125:27)
    at Array.forEach (native)
    at callback (C:\msweb\studioweb\node_modules\webpack\lib\Compilation.js:125:13)
    at module.build (C:\msweb\studioweb\node_modules\webpack\lib\Compilation.js:147:11)
    at ContextModule.<anonymous> (C:\msweb\studioweb\node_modules\webpack\lib\ContextModule.js:118:3)
    at ContextModule.result.resolveDependencies (C:\msweb\angular-cli\packages\@ngtools\webpack\src\plugin.ts:195:25)
    at ContextModule.build (C:\msweb\studioweb\node_modules\webpack\lib\ContextModule.js:99:7)
    at Compilation.buildModule (C:\msweb\studioweb\node_modules\webpack\lib\Compilation.js:127:10)
    at factoryCallback (C:\msweb\studioweb\node_modules\webpack\lib\Compilation.js:304:11)

  

seems the entire stack is from Webpack and no ref to any part of my code

Regards,

Sean

born2net avatar Jan 27 '17 03:01 born2net

I cleared node_modules, rebuilt project and some clean ups and now gone, so closing, regards

born2net avatar Jan 27 '17 13:01 born2net

I'm getting the same error from our codeship build. My local build is fine but it's throwing the same thing exactly. @born2net can you reopen this?

DennisSmolek avatar Feb 03 '17 17:02 DennisSmolek

yes I can, if need to re-close let me know, regards

born2net avatar Feb 03 '17 17:02 born2net

I got this same error when I used yarn to install dependencies instead of npm install. Cleaning node modules and running npm install fixed the problem for me.

isaacplmann avatar Feb 13 '17 17:02 isaacplmann

I'll need a simple repro to investigate this if someone has it.

filipesilva avatar Mar 13 '17 16:03 filipesilva

I had the issue because i manually installed webpack so i had webpack2.3.1 for a different process in the project and was able to fix it by using webpack~2.2.0. Hope that helps.

stefannegele avatar Mar 23 '17 11:03 stefannegele

@LasTanzen Thanks for the great tip! I just removed webpack from the DevDependencies and it works

eladcandroid avatar Mar 28 '17 07:03 eladcandroid

Same as @LasTanzen. Received this error today after upgrading to CLI 1.0.0 (and Angular 4.0.0). Putting Webpack at ~2.2.0 fixed it for me.

brockklein avatar Mar 30 '17 21:03 brockklein

@filipesilva I'm having the problem in this one https://github.com/dancancro/jhipster-sample-app-ng2/tree/newmodules

I tried changing to Webpack ~2.2.0 but that didn't do anything. I also tried removing Webpack from DevDependencies and got Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin'

It happens with ng build. I get a different problem with ng build --aot

// ♥ ng -v
    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.0.0
node: 7.5.0
os: darwin x64
@angular/animations: 4.0.1
@angular/common: 4.0.0
@angular/compiler: 4.0.0
@angular/core: 4.0.0
@angular/flex-layout: 2.0.0-rc.1
@angular/forms: 4.0.0
@angular/http: 4.0.0
@angular/material: 2.0.0-beta.2
@angular/platform-browser: 4.0.0
@angular/platform-browser-dynamic: 4.0.0
@angular/router: 4.0.0
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.0

dancancro avatar Apr 24 '17 18:04 dancancro

@filipesilva Sorry I hadn't seen your solution from the other issue. Changing

  imports: [RouterModule.forRoot(routes, { useHash: true })],

to

  imports: [RouterModule],

eliminated that error. I have other problems with routing so I can't say for sure whether this has any bad consequences.

I had been getting this error:

ERROR Error: Uncaught (in promise): Error: Cannot find module './contact/contact.module'.

After making the above change, I am getting this one instead:

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'module/contacts'

dancancro avatar Apr 24 '17 18:04 dancancro

Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular CLI version.

If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.

filipesilva avatar May 22 '17 15:05 filipesilva

"dependencies": { "@angular/common": "^4.0.0", "@angular/compiler": "^4.0.0", "@angular/core": "^4.0.0", "@angular/forms": "^4.0.0", "@angular/http": "^4.0.0", "@angular/platform-browser": "^4.0.0", "@angular/platform-browser-dynamic": "^4.0.0", "@angular/router": "^4.0.0", "core-js": "^2.4.1", "rxjs": "^5.1.0", "typescript": "^2.3.4", "zone.js": "^0.8.4"} An error occured during the build: Error: No module factory available for dependency type: ContextElementDependency. Happens when trying to use LazyLoading!!! const routes: Routes = [ { path: '', component: HomeComponent }, { path: 'dashboard', loadChildren: './../modules/dashboard/dashboard#DashboardModule' }, { path: '', redirectTo: '', pathMatch: 'full' }, { path: '**', redirectTo: '' },

]; why???? T. F?

Max-Lev avatar Jun 04 '17 22:06 Max-Lev

I am running into this issue when trying to upgrade my angular project to universal using Everton Roberto Auler's angular-cli-demo.

@angular/cli: 1.1.3 node: 6.10.0 os: linux x64 @angular/animations: 4.2.4 @angular/common: 4.2.4 @angular/compiler: 4.2.4 @angular/compiler-cli: 4.2.4 @angular/core: 4.2.4 @angular/forms: 4.2.4 @angular/http: 4.2.4 @angular/platform-browser: 4.2.4 @angular/platform-browser-dynamic: 4.2.4 @angular/platform-server: 4.2.4 @angular/router: 4.2.4 @angular/cli: 1.1.3

I am using webpack ~2.2.0 as you can see here and I have read above this problem was supposed to be obsolete due to recent changes in cli. "tslint": "~4.5.0", "typescript": "~2.2.0", "webpack": "~2.2.0", "webpack-node-externals": "^1.5.4"

But when running "ng build && ngc && webpack" I get this error message: Error: No module factory available for dependency type: ContextElementDependency at Compilation.addModuleDependencies (/www/dev2/front-end/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:206:21)...

Thanks.

Edit: after digging more into the issue, it seems the template compiler don't create ngfactory.ts files for some of my components. Can't figure out why. It happens since webpack was installed.

Norbert1001001 avatar Jun 23 '17 01:06 Norbert1001001

I am having the same issue. Everything works fine on my local machine.

but not on my travis build. when i use ng build for travis , it throws the following error

"Error: No module factory available for dependency type: ContextElementDependency at Compilation.addModuleDependencies"

node: 6.10.0 @angular/cli 1.1.3 webpack 2.6.1

eskinderg avatar Jun 26 '17 23:06 eskinderg

Try reinstalling webpack. It worked for me. It seems it has some issues building factories for new components sometimes and needs to be reinstalled. So I did:

  • npm uninstall --save-dev webpack
  • rm -rf node_modules
  • npm cache clean
  • npm install And after than I didn't get the issue anymore.

Hope it helps.

Norbert1001001 avatar Jun 27 '17 00:06 Norbert1001001

Everything is working fine on my local machine. The problem occurs when i try to build it on travis. And from my understanding, i think travis recreates the node_modules folder on every build.

eskinderg avatar Jun 27 '17 00:06 eskinderg

Is it possible to reopen this issue. please see my output on travis. https://travis-ci.org/eskinderg/Angular2 Even though it is working on my local windows 10 machine, it's failing on travis and i could not figure out what. Thanks.

eskinderg avatar Jun 27 '17 16:06 eskinderg

This issue should definitely remain open. I persistently get this error, with or without AOT compilation, following recent upgrades to Angular CLI and Webpack. Still sticking to Angular 2.4.6 prior to update to 4.0.0.

Error: No module factory available for dependency type: ContextElementDependency

@angular/cli: 1.2.0 node: 8.1.3 os: win32 x64 @angular/common: 2.4.6 @angular/compiler: 2.4.6 @angular/core: 2.4.6 @angular/flex-layout: 2.0.0-rc.1 @angular/forms: 2.4.6 @angular/http: 2.4.6 @angular/material: 2.0.0-beta.2 @angular/platform-browser: 2.4.6 @angular/platform-browser-dynamic: 2.4.6 @angular/platform-server: 2.4.6 @angular/router: 3.4.6 @angular/cli: 1.2.0 @angular/compiler-cli: 2.4.6

Webpack: 3.0.0

ghost avatar Jul 05 '17 11:07 ghost

I forgot to mention that I have repeatedly cleaned and reinstalled node modules, tried global versus local installs of CLI and Webpack etc...

npm cache clean --force rimraf -rf node_modules npm install

My package.json was originally that provided by Angular Class with subsequent upgrades and additions.

David @ Exertive

ghost avatar Jul 05 '17 11:07 ghost

I downgraded my local and global @angular/cli to 1.0.4, Removed all the scripts in the packages.json file that were created during the ng enject process including webpack.config.json. Removed node_moudles and ran npm install again and everything is now working fine.

Hope that helps.

eskinderg avatar Jul 05 '17 12:07 eskinderg