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 have similar problem

Angular - 4.2.5 AngularCLI - 1.2.0 Webpack - 3.1.0

[ERROR]  12% building modules 21/28 modules 7 active ...de_modules\css-loader\lib\cs
 13% building modules 29/43 modules 14 active ...src\app\components\app.component.html
[ERROR] An error occured during the build:
[ERROR] Error: No module factory available for dependency type: ContextElementDependency
[ERROR]     at Compilation.addModuleDependencies (E:\WorkSpase\improver\browser\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:206:21)
[ERROR]     at Compilation.processModuleDependencies (E:\WorkSpase\improver\browser\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:195:8)
[ERROR]     at _this.buildModule.err (E:\WorkSpase\improver\browser\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:336:13)
[ERROR]     at building.forEach.cb (E:\WorkSpase\improver\browser\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:140:27)
[ERROR]     at Array.forEach (native)
[ERROR]     at callback (E:\WorkSpase\improver\browser\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:140:13)
[ERROR]     at module.build (E:\WorkSpase\improver\browser\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:167:11)
[ERROR]     at resolveDependencies (E:\WorkSpase\improver\browser\node_modules\@angular\cli\node_modules\webpack\lib\ContextModule.js:133:4)
[ERROR]     at ContextModule.result.resolveDependencies (E:\WorkSpase\improver\browser\node_modules\@ngtools\webpack\src\plugin.js:229:25)
[ERROR]     at ContextModule.build (E:\WorkSpase\improver\browser\node_modules\@angular\cli\node_modules\webpack\lib\ContextModule.js:103:8)
[ERROR]     at Compilation.buildModule (E:\WorkSpase\improver\browser\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:142:10)
[ERROR]     at factoryCallback (E:\WorkSpase\improver\browser\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:325:11)
[ERROR]     at E:\WorkSpase\improver\browser\node_modules\@angular\cli\node_modules\webpack\lib\ContextModuleFactory.js:96:12
[ERROR]     at E:\WorkSpase\improver\browser\node_modules\tapable\lib\Tapable.js:204:11
[ERROR]     at done.then (E:\WorkSpase\improver\browser\node_modules\@ngtools\webpack\src\plugin.js:231:28)
[ERROR]     at <anonymous>

Halynsky avatar Jul 08 '17 12:07 Halynsky

same issue here

npm ls -g --depth=0

/usr/lib
├── [email protected]
└── [email protected]

package.json:

  "dependencies": {
    "@angular/animations": "^4.3.0",
    "@angular/cdk": "github:angular/cdk-builds",
    "@angular/common": "^4.3.0",
    "@angular/compiler": "^4.3.0",
    "@angular/core": "^4.3.0",
    "@angular/flex-layout": "angular/flex-layout-builds",
    "@angular/forms": "^4.3.0",
    "@angular/http": "^4.3.0",
    "@angular/material": "angular/material2-builds",
    "@angular/platform-browser": "^4.3.0",
    "@angular/platform-browser-dynamic": "^4.3.0",
    "@angular/platform-server": "^4.3.0",
    "@angular/router": "^4.3.0",
    "angular2gridster": "^0.6.3",
    "core-js": "^2.4.1",
    "hammerjs": "^2.0.8",
    "rxjs": "^5.0.1",
    "zone.js": "^0.8.12"
  },
  "devDependencies": {
    "@angular/cli": "^1.2.3",
    "@angular/compiler-cli": "^4.3.0",
    "@types/jasmine": "2.5.46",
    "@types/node": "~7.0.12",
    "codelyzer": "~3.0.1",
    "simple-git": "^1.69.0",
    "simple-terminal-menu": "^1.1.3",
    "ts-node": "~3.0.4",
    "tslint": "^5.3.2",
    "typescript": "^2.4.1"
  }

ng serve

12% building modules 17/29 modules 12 active ...art/node_modules/zone.js/dist/zone.jsError: No module factory available for dependency type: ContextElementDependency
    at Compilation.addModuleDependencies (/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:206:21)
    at Compilation.processModuleDependencies (/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:195:8)
    at _this.buildModule.err (/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:336:13)
    at building.forEach.cb (/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:140:27)
    at Array.forEach (native)
    at callback (/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:140:13)
    at module.build (/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:167:11)
    at resolveDependencies (/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/ContextModule.js:133:4)
    at ContextModule.result.resolveDependencies (/home/mike_oldfield/material2-start/node_modules/@ngtools/webpack/src/plugin.js:249:25)
    at ContextModule.build (/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/ContextModule.js:103:8)
    at Compilation.buildModule (/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:142:10)
    at factoryCallback (/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:325:11)
    at /home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/ContextModuleFactory.js:96:12
    at /home/mike_oldfield/material2-start/node_modules/tapable/lib/Tapable.js:250:11
    at done.then (/home/mike_oldfield/material2-start/node_modules/@ngtools/webpack/src/plugin.js:251:28)               13% building modules 29/36 modules 7 active ...terial2-start/node_modules/rxjs/Rx.js/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:265
                                if(_this.profile) {
                                        ^

TypeError: Cannot read property 'profile' of null
    at factoryCallback (/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:265:13)
    at factory (/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/NormalModuleFactory.js:253:5)
    at applyPluginsAsyncWaterfall (/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/NormalModuleFactory.js:99:14)
    at /home/mike_oldfield/material2-start/node_modules/tapable/lib/Tapable.js:250:11
    at NormalModuleFactory.params.normalModuleFactory.plugin (/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/CompatibilityPlugin.js:52:5)
    at NormalModuleFactory.applyPluginsAsyncWaterfall (/home/mike_oldfield/material2-start/node_modules/tapable/lib/Tapable.js:254:13)
    at resolver (/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/NormalModuleFactory.js:74:11)
    at process.nextTick (/home/mike_oldfield/material2-start/node_modules/@angular/cli/node_modules/webpack/lib/NormalModuleFactory.js:205:8)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)

source repository: https://github.com/rudzikdawid/material2-start

rudzikdawid avatar Jul 22 '17 08:07 rudzikdawid

We have the samme issue

We are runnning:

Node 8.1.4 Angular CLI 1.3.2

When I do a npm list webpack, I get:

--- @angular/[email protected] [email protected] [email protected]

My package.json looks like this:

"dependencies": {
"@angular/animations": "^4.3.4",
"@angular/common": "^4.1.0",
"@angular/compiler": "^4.1.0",
"@angular/core": "^4.1.0",
"@angular/forms": "^4.1.0",
"@angular/http": "^4.1.0",
"@angular/platform-browser": "^4.1.0",
"@angular/platform-browser-dynamic": "^4.1.0",
"@angular/router": "^4.1.0",
"@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.26",
"@ngx-translate/core": "^6.0.1",
"@ngx-translate/http-loader": "0.0.3",
"@types/lodash": "^4.14.72",
"@types/moment": "^2.13.0",
"@types/socket.io-client": "^1.4.29",
"angular-progress-http": "^0.5.1",
"angular-svg-round-progressbar": "^1.1.0",
"angular2-moment": "^1.3.3",
"angular2-recaptcha": "^0.6.0",
"angular2-sails": "^0.2.8",
"bootstrap": "^3.3.7",
"chart.js": "^2.5.0",
"core-js": "^2.4.1",
"font-awesome": "^4.7.0",
"lodash": "^4.17.4",
"moment": "^2.18.1",
"ng2-charts": "^1.5.0",
"ng2-file-upload": "^1.2.1",
"ngx-bootstrap": "^2.0.0-beta.4",
"ngx-file-drop": "^1.0.10",
"ngx-popper": "^1.1.0",
"rxjs": "^5.1.0",
"socket.io-client": "^1.7.3",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/cli": "^1.0.4",
"@angular/compiler-cli": "^4.1.0",
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^0.2.0",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": ", ~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "~2.2.0",
"webpack": "^3.4.1"
}

We have tried uninstalling webpack, but then we get another error (cant find webpack issue).

Has anyone any ideas how to fix this?

ChrisWorks avatar Sep 13 '17 17:09 ChrisWorks

Heya, see https://github.com/angular/angular-cli/issues/6417 for information about what causes this problem and how to fix it.

filipesilva avatar Sep 13 '17 19:09 filipesilva

I had a problem when the @angular/cli module version I had was 1.3.0. All the problems were solved when I ran the npm i @angular/cli --save-dev command. Try this and Please write a comment~👍

ehdwns980416 avatar Feb 16 '18 04:02 ehdwns980416

I updated the angular cli to latest version and this working for me. angular cli before 1.3.2 angular cli after 1.7.2

image

rubenspl avatar Mar 01 '18 05:03 rubenspl

i had to set a version for webpack https://github.com/angular/angular-cli/issues/9794#issuecomment-371909824

mariohmol avatar Mar 28 '18 01:03 mariohmol

  1. Package.json: remove webpack from DevDependencies
  2. rm -R node_modules (remove node_modules folder)
  3. npm i -g webpack
  4. npm i -g webpack-dev-server
  5. remove package-lock.json (if it’s there)
  6. npm i
  7. npm start

Reference:http://dxtright.com/index.php/2017/12/05/angular-no-module-factory-available-dependency-type-contextelementdependency/

joleelu avatar Jun 08 '18 09:06 joleelu

  1. Package.json: remove webpack from DevDependencies
  2. rm -R node_modules (remove node_modules folder)
  3. npm i -g webpack
  4. npm i -g webpack-dev-server
  5. remove package-lock.json (if it’s there)
  6. npm i
  7. npm start

Reference:http://dxtright.com/index.php/2017/12/05/angular-no-module-factory-available-dependency-type-contextelementdependency/

your solution is not work for me :(

1- Update Angular cli 2- Update Node.js 3- Rm node_modules 4- npm i 5- ng build --prod --aot

but same error : Runtime compiler is not loaded

KeyvanAghaie avatar Jun 11 '19 07:06 KeyvanAghaie

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.