angular-cli: 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! ngnode-fullstack@0.0.1 build:prod: `ng build --prod`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ngnode-fullstack@0.0.1 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

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 25
  • Comments: 53 (5 by maintainers)

Commits related to this issue

Most upvoted comments

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”

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

@hansl just tried it out with following package.json:

  "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",
    "@ngrx/core": "^1.2.0",
    "@ngrx/store": "^2.2.1",
    "@ngrx/store-devtools": "^3.2.3",
    "core-js": "^2.4.1",
    "rxjs": "^5.1.0",
    "ts-helpers": "^1.1.1",
    "typings": "^2.1.0",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@angular/cli": "1.0.0",
    "@angular/compiler-cli": "^4.0.0",
    "@types/jasmine": "2.5.38",
    "@types/node": "~6.0.60",
    
    // some others ...

    "typescript": "~2.2.0"
  }

Still having this issue on ng build --aot

ERROR in ./src/$$_gendir async
Module not found: Error: Can't resolve 'myproject/src/$$_gendir/app/home/signup/signup.module.ngfactory.ts' in 'myproject/src/$$_gendir'
 @ ./src/$$_gendir async
 @ ./~/@angular/core/@angular/core.es5.js
 @ ./src/main.ts
 @ multi ./src/main.ts

Slightly different stacktrace, but same error (using ng4):

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/Users/myuser/projects/myapp/src'
 @ ./src/main.ts 5:0-74
 @ multi ./src/main.ts

great, congrats!

but can you tell me what you’ve changed?

I am using lazy loading in my application and getting same error while creating production build. I was doing ng build --prod (giving error)

but once I tried ng build --environment prod (it’s working properly)

for me not work with target (ng build --prod), but working with: ng build --environment prod

use @angular/cli@1.2.6 solved my problem!

@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?

ps: I’m only having this issue when i add the files parameter to tsconfig.app.json file.

--env=prod and --prod are not the same thing. See https://github.com/angular/angular-cli/issues/7113#issuecomment-317472732 for some information about that.

make sure your app running with the same cli version that you have created the app, that’s the problem what I met.

@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.

@asadsahi yep did that, i’m working with angular cli 1.0, and angular 4.0 and once i add the files to tsconfig.app.json i cannot build with ng build --aot.

i did the same in a brand new project and it’s the same.

please try this command “npm i enhanced-resolve@3.3.0”

@Eikc Exactly the same issue, seems it’s become pretty common… angular 4.2.4 + angular/cli 1.3.2 + typescript 2.4.2

I have been recieiving the following after i tried to lazy load my modules for a project of mine:

ERROR in ./src/$$_gendir lazy Module not found: Error: Can’t resolve ’ src$$_gendir\app\products\product.module.ngfactory.ts’ in ’ src$$_gendir’ resolve ’ src$$_gendir\app\products\product.module.ngfactory.ts’ in ’ src$$_gendir’ using description file: package.json (relative path: ./src/$$_gendir) Field ‘browser’ doesn’t contain a valid alias configuration after using description file: package.json (relative path: ./src/$$_gendir) using description file: package.json (relative path: ./src/$$_gendir/app/products/product.module.ngfactory.ts) no extension Field ‘browser’ doesn’t contain a valid alias configuration src$$_gendir\app\products\product.module.ngfactory.ts doesn’t exist .ts Field ‘browser’ doesn’t contain a valid alias configuration src$$_gendir\app\products\product.module.ngfactory.ts.ts doesn’t exist .js Field ‘browser’ doesn’t contain a valid alias configuration src$$_gendir\app\products\product.module.ngfactory.ts.js doesn’t exist as directory src$$_gendir\app\products\product.module.ngfactory.ts doesn’t exist [ src$$_gendir\app\products\product.module.ngfactory.ts] [ src$$_gendir\app\products\product.module.ngfactory.ts.ts] [ src$$_gendir\app\products\product.module.ngfactory.ts.js] [ src$$_gendir\app\products\product.module.ngfactory.ts] @ ./src/$$_gendir lazy @ ./node_modules/@angular/core/@angular/core.es5.js @ ./src/main.ts @ multi ./src/main.ts

and i tried all of the different approaches, even changing the enhanced-resolve package… Nothing worked… but one thing I noticed was that I actually had my “product” module within a Product folder (with capital P). When I changed the folder naming to lowercase… my two modules that gave the above error started to compile in --prod mode…

I don’t know if this will help anyone but it sure fixed my issues with angular cli AOT / prod

I have been recieiving the following after i tried to lazy load my modules for a project of mine:

ERROR in ./src/$$_gendir lazy Module not found: Error: Can’t resolve ’ src$$_gendir\app\products\product.module.ngfactory.ts’ in ’ src$$_gendir’ resolve ’ src$$_gendir\app\products\product.module.ngfactory.ts’ in ’ src$$_gendir’ using description file: package.json (relative path: ./src/$$_gendir) Field ‘browser’ doesn’t contain a valid alias configuration after using description file: package.json (relative path: ./src/$$_gendir) using description file: package.json (relative path: ./src/$$_gendir/app/products/product.module.ngfactory.ts) no extension Field ‘browser’ doesn’t contain a valid alias configuration src$$_gendir\app\products\product.module.ngfactory.ts doesn’t exist .ts Field ‘browser’ doesn’t contain a valid alias configuration src$$_gendir\app\products\product.module.ngfactory.ts.ts doesn’t exist .js Field ‘browser’ doesn’t contain a valid alias configuration src$$_gendir\app\products\product.module.ngfactory.ts.js doesn’t exist as directory src$$_gendir\app\products\product.module.ngfactory.ts doesn’t exist [ src$$_gendir\app\products\product.module.ngfactory.ts] [ src$$_gendir\app\products\product.module.ngfactory.ts.ts] [ src$$_gendir\app\products\product.module.ngfactory.ts.js] [ src$$_gendir\app\products\product.module.ngfactory.ts] @ ./src/$$_gendir lazy @ ./node_modules/@angular/core/@angular/core.es5.js @ ./src/main.ts @ multi ./src/main.ts

and i tried all of the different approaches, even changing the enhanced-resolve package… Nothing worked… but one thing I noticed was that I actually had my “product” module within a Product folder (with capital P). When I changed the folder naming to lowercase… my two modules that gave the above error started to compile in --prod mode…

I don’t know if this will help anyone but it sure fixed my issues with angular cli AOT / prod

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

When putting it inside, it works.

but then the compiler cannot find the namespaces declared in the typings file…