Start-ios-bundle can not find app.module.ngfactory


#1

Hello, I want to use webpack to bundle my project, but when I run this command:
npm run start-ios-bundle
I got this error:

ERROR in ./main.aot.ts
Module not found: Error: Can’t resolve ‘./app.module.ngfactory’ in ‘/Users/test//app’
@ ./main.aot.ts 5:29-62

I googled a lot, someone mentioned to change zone to 0.8.14, others mentioned to use “enhanced-resolve”: “3.3.0”, or “@ngtools/webpack”: “1.5.3”, but nothing is working here.

My package.json is:

“dependencies”: {
"@angular/animations": “~4.2.0”,
"@angular/common": “~4.2.0”,
"@angular/compiler": “~4.2.0”,
"@angular/core": “~4.2.0”,
"@angular/forms": “~4.2.0”,
"@angular/http": “~4.2.0”,
"@angular/platform-browser": “~4.2.0”,
"@angular/router": “~4.2.0”,
“loose-envify”: “^1.3.1”,
“mkdirp”: “^0.5.1”,
“nativescript-angular”: “~4.2.0”,
“nativescript-audio”: “^3.5.0”,
“nativescript-email”: “^1.5.1”,
“nativescript-iqkeyboardmanager”: “^1.1.0”,
“nativescript-pro-ui”: “^3.1.2”,
“nativescript-social-share”: “^1.4.0”,
“nativescript-sqlite”: “^1.1.9”,
“nativescript-theme-core”: “~1.0.2”,
“nativescript-xml2js”: “^0.5.2”,
“reflect-metadata”: “~0.1.8”,
“rxjs”: “~5.4.2”,
“tns-core-modules”: “3.2.0”,
“zone.js”: “0.8.14”
},
“devDependencies”: {
"@angular/compiler-cli": “~4.2.0”,
"@ngtools/webpack": “~1.6.0”,
“babel-traverse”: “6.26.0”,
“babel-types”: “6.26.0”,
“babylon”: “6.18.0”,
“copy-webpack-plugin”: “~4.0.1”,
“extract-text-webpack-plugin”: “~3.0.0”,
“lazy”: “1.0.11”,
“nativescript-css-loader”: “~0.26.0”,
“nativescript-dev-typescript”: “~0.5.0”,
“nativescript-dev-webpack”: “^0.8.0”,
“nativescript-worker-loader”: “~0.8.1”,
“raw-loader”: “~0.5.1”,
“resolve-url-loader”: “~2.1.0”,
“tns-platform-declarations”: “^3.2.0”,
“typescript”: “~2.4.2”,
“webpack”: “~3.2.0”,
“webpack-bundle-analyzer”: “^2.8.2”,
“webpack-sources”: “~1.0.1”,
“enhanced-resolve”: “3.3.0”
},
“scripts”: {
“ns-bundle”: “ns-bundle”,
“publish-ios-bundle”: “npm run ns-bundle --ios --publish-app”,
“generate-android-snapshot”: “generate-android-snapshot --targetArchs arm,arm64,ia32 --install”,
“start-android-bundle”: “npm run ns-bundle --android --run-app”,
“start-ios-bundle”: “npm run ns-bundle --ios --run-app”,
“build-android-bundle”: “npm run ns-bundle --android --build-app”,
“build-ios-bundle”: “npm run ns-bundle --ios --build-app”
}
}

Any ideal how to improve this?


#2

Do you have a public repository?


#3

Resolved by:

  1. “webpack”: “~3.4.1”,
  2. Adding below to each module:
    moduleId: module.id
  3. using relative path:

@Component({
moduleId: module.id,
templateUrl: “./db.component.html”,
styleUrls: [’./db.component.css’]
})

And then resolve any error thrown in the console.

The error:
Can’t resolve ‘./app.module.ngfactory’ in ‘/Users/test//app’
@ ./main.aot.ts 5:29-62

is really NOT the error it really means, it is there because other module
template/css etc can not be found