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

ng build --prod give Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'C:\projectpath\src'

Open asadsahi opened this issue 9 years ago • 53 comments

- [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

asadsahi avatar Mar 23 '17 16:03 asadsahi

I'm seeing this as well. Seems like something changed in Angular 4.0.0-rc.6. If you downgrade to rc.5 production builds work again.

trevor-hackett avatar Mar 23 '17 20:03 trevor-hackett

@chuckjaz just confirmed that this error has been solved on @angular/angular master and will be in Angular 4.0 final.

hansl avatar Mar 24 '17 00:03 hansl

Heya, I'm told that this was a bug in Angular 4.0.0-rc.6 and that i's now fixed. I'm sorry but I don't have an issue to link here. It should be out next release.

filipesilva avatar Mar 24 '17 00:03 filipesilva

@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

emreavsar avatar Mar 24 '17 12:03 emreavsar

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

binarious avatar Mar 24 '17 13:03 binarious

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

emreavsar avatar Mar 24 '17 14:03 emreavsar

Hi guys, Good, news. Its work for me now. Both builds, jit prod & aot prod are working. there are some errors on 1 - 2 pages when running the aot version, which I suspect something wrong with my code, but I have to dig a little deeper to find out what are those, but cli is building both outputs perfectly this time.

I am on angular 4 and cli 1 final.

asadsahi avatar Mar 24 '17 14:03 asadsahi

great, congrats!

but can you tell me what you've changed?

emreavsar avatar Mar 24 '17 15:03 emreavsar

@emreavsar I haven't modiefied config wise in my project to make it work, just angular/cli and angular packages upgraded to 1 and 4 respectively.

If you are using angular cli the default tsconfig.app.json doesn't have files config in it. Just excluding e2e and spec files in exclude settings.

I also uninstalled global angular/cli package and then installed 1.0.0 globally as well.

One thing I haven't tried is doing npm install with yarn. I have rimraf node_modules from my project and then just did npm install.

asadsahi avatar Mar 24 '17 15:03 asadsahi

One thing also worth trying to generate a new cli project and quickly compare the settings of your local project with the new one. I have been doing the same since all the last releases of cli and always finding something has changed in config file. e.g final vs last rc, tsconfig.json files are slightly different.

asadsahi avatar Mar 24 '17 15:03 asadsahi

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

emreavsar avatar Mar 24 '17 15:03 emreavsar

A brand new cli project's aot build succeeded on my machine as well.

image

I am on window 7 with node 6.10.0. So I am guessing something different environment wise perhaps?

asadsahi avatar Mar 24 '17 16:03 asadsahi

with the files in tsconfig.app.json ?

emreavsar avatar Mar 24 '17 16:03 emreavsar

nope, default cli doesn't have files config in tsconfig.app.json. BTW do you need to specify files in config files?

asadsahi avatar Mar 24 '17 16:03 asadsahi

Without it works as well for me, after adding files it does not work.

I have local (non npm) typings, which i need in my project:

{
  "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"
  ]
}

emreavsar avatar Mar 24 '17 16:03 emreavsar

can you try adding your custom typings in src/typings.d.ts file (default d.ts file generated by cli)?

asadsahi avatar Mar 24 '17 16:03 asadsahi

@emreavsar you have the files in the wrong spot in the tsconfig.app.json file. It needs to be inside the compilerOptions object. Putting it outside produces the error that you're seeing.

trevor-hackett avatar Mar 24 '17 16:03 trevor-hackett

Valid configuration would look like this:

{
  "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"
  ]
}

trevor-hackett avatar Mar 24 '17 16:03 trevor-hackett

@yarrgh wrong belief :). Not inside compiler options. Schema isn't validated. files is available as root element.

asadsahi avatar Mar 24 '17 16:03 asadsahi

True, but try placing it inside and see if ng build --aot works. I'm using files as well. If i place it outside, that error appears. I put it in compilerOptions it compiles. May be a bug?

trevor-hackett avatar Mar 24 '17 16:03 trevor-hackett