ng build --prod give Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'C:\projectpath\src'
- [x ] bug report
Versions.
@angular/*": "4.0.0-rc.6
@angular/cli: 1.0.0-rc.4 node: 6.9.1 os: win32 x64 Windows 7 And Window 10
Repro steps.
Just run ng build --prod
The log given by the failure.
dules/@ng-bootstrap/ng-bootstrap/util/util.d.ts
Hash: b8b958c29762fa762c34
Time: 11764ms
chunk {0} polyfills.62c31de27797344f09a6.bundle.js (polyfills) 158 kB {5} [initial] [rendered]
chunk {1} main.0080928b6a891ad4f45d.bundle.js (main) 3.21 kB {4} [initial] [rendered]
chunk {2} styles.4001f4f573259b290c26.bundle.css (styles) 175 bytes {5} [initial] [rendered]
chunk {3} sw-register.b73048fe3d9f8a1e7ae5.bundle.js (sw-register) 232 bytes {5} [initial] [rendered]
chunk {4} vendor.87c63162470e632861f4.bundle.js (vendor) 960 kB [initial] [rendered]
chunk {5} inline.ce192cec606fd32293a6.bundle.js (inline) 0 bytes [entry] [rendered]
ERROR in m.replace is not a function
ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'C:\Users\asahi\ngnode-fullstack\src'
@ ./src/main.ts 5:0-74
@ multi ./src/main.ts
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build:prod"
npm ERR! node v6.9.1
npm ERR! npm v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! [email protected] build:prod: `ng build --prod`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build:prod script 'ng build --prod'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ngnode-fullstack package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ng build --prod
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs ngnode-fullstack
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls ngnode-fullstack
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\asahi\ngnode-fullstack\npm-debug.log
Desired functionality.
Should produce production build
Ill try it out at home.
@yarrgh the reason why it might be compiling is because it is ignoring those files at all. If it is working it might well be a typescript bug unless I am missing something.
Yeah it is really strange. Doubling it up to where it is both inside and outside of compilerOptions works as well. It seems like the compiler doesn't like it unless it is at least inside the compilerOptions
Works: (only inside compilerOptions)
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"baseUrl": "",
"types": [],
"typeRoots": [
"../node_modules/@types"
],
"files": [
"../typings/index.d.ts"
]
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
Works: (both inside and outside compilerOptions)
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"baseUrl": "",
"types": [],
"typeRoots": [
"../node_modules/@types"
],
"files": [
"../typings/index.d.ts"
]
},
"exclude": [
"test.ts",
"**/*.spec.ts"
],
"files": [
"../typings/index.d.ts"
]
}
Doesn't work: (only outside compilerOptions)
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"baseUrl": "",
"types": [],
"typeRoots": [
"../node_modules/@types"
]
},
"exclude": [
"test.ts",
"**/*.spec.ts"
],
"files": [
"../typings/index.d.ts"
]
}
When putting it inside, it works.
but then the compiler cannot find the namespaces declared in the typings file...
@emreavsar when you add the files array, you're telling TS that those are the entry points for your project - and only those!
Instead, try using the include property.
Jep also read about that in the meanwhile, but it does not change anything, same result.
@emreavsar can you open a new issue with a simple repro please? That way we can investigate.
@asadsahi I'm facing the errors but I'm lazy loading modules. It seems it can't find the modules I'm trying to lazy loading. This is my routes setup:
app-routing.ts
export const routes: Routes = [
{ path: '', component: HomeComponent },
{
// path: '*/p-:ssin',
matcher: pdpURLMatcher,
loadChildren: './+pdp#PDPModule'
},
{
// path: '*/p-:ssin/bundle',
path: 'bundle',
// matcher: pdpTypeURLMatcher,
loadChildren: './+pdp/+bundle#BundleModule'
},
{
// path: '*/p-:ssin/collection',
path: 'collection',
// matcher: pdpTypeURLMatcher,
loadChildren: './+pdp/+collection#CollectionModule'
},
{
// path: '*/p-:ssin/single-product',
path: 'single-product',
// matcher: pdpTypeURLMatcher,
loadChildren: './+pdp/+single-product#SingleProductModule'
},
ng build --prod errors:
ERROR in ./src/$$_gendir async
Module not found: Error: Can't resolve '/Users/spate42/Projects/NewHorizon/src/$$_gendir/app/+pdp/index.ngfactory.ts' in '/Users/spate42/Projects/NewHorizon/src/$$_gendir'
@ ./src/$$_gendir async
@ ./~/@angular/core/@angular/core.es5.js
@ ./src/main.ts
@ multi ./src/main.ts
ERROR in ./src/$$_gendir async
Module not found: Error: Can't resolve '/Users/spate42/Projects/NewHorizon/src/$$_gendir/app/+pdp/+bundle/index.ngfactory.ts' in '/Users/spate42/Projects/NewHorizon/src/$$_gendir'
@ ./src/$$_gendir async
@ ./~/@angular/core/@angular/core.es5.js
@ ./src/main.ts
@ multi ./src/main.ts
ERROR in ./src/$$_gendir async
Module not found: Error: Can't resolve '/Users/spate42/Projects/NewHorizon/src/$$_gendir/app/+pdp/+collection/index.ngfactory.ts' in '/Users/spate42/Projects/NewHorizon/src/$$_gendir'
@ ./src/$$_gendir async
@ ./~/@angular/core/@angular/core.es5.js
@ ./src/main.ts
@ multi ./src/main.ts
ERROR in ./src/$$_gendir async
Module not found: Error: Can't resolve '/Users/spate42/Projects/NewHorizon/src/$$_gendir/app/+pdp/+single-product/index.ngfactory.ts' in '/Users/spate42/Projects/NewHorizon/src/$$_gendir'
@ ./src/$$_gendir async
@ ./~/@angular/core/@angular/core.es5.js
@ ./src/main.ts
@ multi ./src/main.ts
package.json:
"dependencies": {
"@angular-redux/router": "^6.0.1",
"@angular-redux/store": "^6.0.1",
"@angular/animations": "^4.0.0-rc.6",
"@angular/common": "^4.0.0-rc.6",
"@angular/compiler": "^4.0.0-rc.6",
"@angular/compiler-cli": "^4.0.0-rc.6",
"@angular/core": "^4.0.0-rc.6",
"@angular/forms": "^4.0.0-rc.6",
"@angular/http": "^4.0.0-rc.6",
"@angular/platform-browser": "^4.0.0-rc.6",
"@angular/platform-browser-dynamic": "^4.0.0-rc.6",
"@angular/platform-server": "^4.0.0-rc.6",
"@angular/router": "^4.0.0-rc.6",
"core-js": "^2.4.1",
"redux": "^3.6.0",
"rxjs": "^5.1.0",
"typescript": "^2.2.2",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/cli": "1.0.0",
"@angular/compiler-cli": "^4.0.0-rc.6",
"@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.0.0",
"zone.js": "^0.7.8"
}
Is there anything special I have to do to get aot working?
I got similar Error both in angualr 2 and angular 4
ERROR in Unexpected value 'null' declared by the module 'PageModule in /Users/laurel/git/Nanhua.IOT/IOT-master/src/client2/src/app/pages/routing.module.ts'
ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/Users/laurel/git/Nanhua.IOT/IOT-master/src/client2/src' @ ./src/main.ts 4:0-74 @ multi ./src/main.ts
ng build --prod --aot=false executes without problems.
Or can use ng build --env=prod Instead of ng build --prod
Follow https://github.com/angular/angular-cli/issues/4551
Strange this issue is closed. I still have the issue with angular cli 1.0.1 (tried with 1.0.0 as well) and angular 4.0.1 (tried with 4.0.0 as well).
- angular & npm version:
C:\temp>ng --version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
@angular/cli: 1.0.1
node: 7.8.0
os: win32 x64
- generate new project
C:\temp>ng new aot-test
installing ng
create .editorconfig
create README.md
create src\app\app.component.css
create src\app\app.component.html
create src\app\app.component.spec.ts
create src\app\app.component.ts
create src\app\app.module.ts
create src\assets\.gitkeep
create src\environments\environment.prod.ts
create src\environments\environment.ts
create src\favicon.ico
create src\index.html
create src\main.ts
create src\polyfills.ts
create src\styles.css
create src\test.ts
create src\tsconfig.app.json
create src\tsconfig.spec.json
create src\typings.d.ts
create .angular-cli.json
create e2e\app.e2e-spec.ts
create e2e\app.po.ts
create e2e\tsconfig.e2e.json
create .gitignore
create karma.conf.js
create package.json
create protractor.conf.js
create tsconfig.json
create tslint.json
Successfully initialized git.
Installing packages for tooling via npm.
Installed packages for tooling via npm.
Project 'aot-test' successfully created.
- build for prod
C:\temp>cd aot-test
C:\temp\aot-test>ng build --prod
Hash: 95aff9eb24de9bebcc2e
Time: 14385ms
chunk {0} polyfills.8f58b700e5aa67ecaabd.bundle.js (polyfills) 166 kB {3} [initial] [rendered]
chunk {1} (styles) 57.2 kB {3} [initial] [rendered]
chunk {2} main.eeb8e498ed00c02e4256.bundle.js (main) 806 kB [initial] [rendered]
chunk {3} inline.0e758da7bdb7782b8654.bundle.js (inline) 0 bytes [entry] [rendered]
ERROR in e:/temp/aot-test/src/main.ts
Module not found: Error: Can't resolve './C:/temp/aot-test/src/$$_gendir/app/app.module.ngfactory' in 'e:\temp\aot-test\src'
@ e:/temp/aot-test/src/main.ts 4:0-95
@ multi ./src/main.ts
- just build with --aot option produces same result
C:\temp\aot-test>ng build --aot
Hash: 97b1fefbef9efc6dfe40
Time: 8204ms
chunk {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 166 kB {3} [initial] [rendered]
chunk {1} styles.bundle.js, styles.bundle.js.map (styles) 57.3 kB {3} [initial] [rendered]
chunk {2} main.bundle.js, main.bundle.js.map (main) 806 kB [initial] [rendered]
chunk {3} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
ERROR in e:/temp/aot-test/src/main.ts
Module not found: Error: Can't resolve './C:/temp/aot-test/src/$$_gendir/app/app.module.ngfactory' in 'e:\temp\aot-test\src'
@ e:/temp/aot-test/src/main.ts 4:0-95
@ multi ./src/main.ts
- build for prod without aot produces even more errors
C:\temp\aot-test>ng build --prod --aot=false
Hash: 7ae0881e2a218dbe00e6
Time: 23575ms
chunk {0} polyfills.8f58b700e5aa67ecaabd.bundle.js (polyfills) 166 kB {3} [initial] [rendered]
chunk {1} (styles) 57.2 kB {3} [initial] [rendered]
chunk {2} main.954ab31011b7607af7a5.bundle.js (main) 2.15 MB [initial] [rendered]
chunk {3} inline.1646bf119902eca70e4b.bundle.js (inline) 0 bytes [entry] [rendered]
ERROR in TypeError: Cannot read property 'match' of undefined
- suppress-entry-chunks-webpack-plugin.js:40 filterFn
[aot-test]/[@angular]/cli/plugins/suppress-entry-chunks-webpack-plugin.js:40:91
- Array.filter
- suppress-entry-chunks-webpack-plugin.js:42 Compilation.compilation.plugin
[aot-test]/[@angular]/cli/plugins/suppress-entry-chunks-webpack-plugin.js:42:59
- Tapable.js:208 Compilation.applyPluginsAsyncWaterfall
[aot-test]/[tapable]/lib/Tapable.js:208:13
- util.js:16 Compilation.tryCatcher
[aot-test]/[bluebird]/js/release/util.js:16:23
- index.js:642
[aot-test]/[html-webpack-plugin]/index.js:642:12
- index.js:152
[aot-test]/[html-webpack-plugin]/index.js:152:16
- util.js:16 tryCatcher
[aot-test]/[bluebird]/js/release/util.js:16:23
- promise.js:512 Promise._settlePromiseFromHandler
[aot-test]/[bluebird]/js/release/promise.js:512:31
- promise.js:569 Promise._settlePromise
[aot-test]/[bluebird]/js/release/promise.js:569:18
- promise.js:614 Promise._settlePromise0
[aot-test]/[bluebird]/js/release/promise.js:614:10
- promise.js:693 Promise._settlePromises
[aot-test]/[bluebird]/js/release/promise.js:693:18
- async.js:133 Async._drainQueue
[aot-test]/[bluebird]/js/release/async.js:133:16
- async.js:143 Async._drainQueues
[aot-test]/[bluebird]/js/release/async.js:143:10
- async.js:17 Immediate.Async.drainQueues
[aot-test]/[bluebird]/js/release/async.js:17:14
- build with --env=prod works, but this is probably not what you want to deploy to production...
C:\temp\aot-test>ng build --env=prod
Hash: 7e625e26338135d76fee
Time: 21628ms
chunk {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 166 kB {3} [initial] [rendered]
chunk {1} styles.bundle.js, styles.bundle.js.map (styles) 57.3 kB {3} [initial] [rendered]
chunk {2} main.bundle.js, main.bundle.js.map (main) 2.15 MB [initial] [rendered]
chunk {3} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
Any suggestions would be highly appreciated!
Ok, so I figured out what's wrong. On my windows machine, the c:\temp folder is linked to e:\temp (using junction: https://technet.microsoft.com/en-us/sysinternals/bb896768.aspx)
C:\>dir /x
Volume in drive C has no label.
Volume Serial Number is 7E77-1C98
Directory of C:\
...
09/03/2016 13:48 <JUNCTION> temp [\??\e:\temp]
...
The errors says:
Module not found: Error: Can't resolve './C:/temp/aot-test/src/$$_gendir/app/app.module.ngfactory' in 'e:\temp\aot-test\src'
When building directly in the e:\temp folder, it works fine:
E:\TEMP\aot-test>ng build --prod
Hash: 4151ffe069ccfe6726cb
Time: 17420ms
chunk {0} polyfills.a826c616902ba35dd8ef.bundle.js (polyfills) 166 kB {4} [initial] [rendered]
chunk {1} main.8e177c429e72a28744b4.bundle.js (main) 21.2 kB {3} [initial] [rendered]
chunk {2} styles.d41d8cd98f00b204e980.bundle.css (styles) 69 bytes {4} [initial] [rendered]
chunk {3} vendor.8b1206c372ceef779894.bundle.js (vendor) 1.1 MB [initial] [rendered]
chunk {4} inline.a467aea5b4249c999b26.bundle.js (inline) 0 bytes [entry] [rendered]
make sure your app running with the same cli version that you have created the app, that's the problem what I met.
Any update on this guys ?
Happens to me when loadChildren is in node_modules. So if the module is installed via npm.
It will look in the wrong directory:
ERROR in ./src/$$_gendir async
Module not found: Error: Can't resolve '/home/.../
src/node_modules/..../index.ngfactory.ts' in '/home/.../src/$$_gendir'
notice /src/node_modules/
Just leaving it here. Solved by https://github.com/angular/angular-cli/issues/7113
Solved by #7113
1.npm clean cache 2. Delete node_modules 3. Add "enhanced-resolve": "3.3.0" in your package.json 4. run npm install then test the command "ng build --prod"
for me not work with target (ng build --prod), but working with: ng build --environment prod
@Apee any idea why this approach works and why this happened? Thanks for the fix!
@brian-singer I have not idea, my guess is that they updated ng-tools but i'm really not sure what happenned too... If someone has the complete explanation i'd be very happy to know what caused this.