NativeScript / nativescript-angular

Integrating NativeScript with Angular
http://docs.nativescript.org/angular/tutorial/ng-chapter-0
Apache License 2.0
1.22k stars 241 forks source link

Webpack.config.js does not exist after ns migrate / can't run the app (shared code project) #2356

Closed plackowski closed 3 years ago

plackowski commented 3 years ago

Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

CLI: 8.0.1 Cross-platform modules: 8.0.5 Android Runtime: ^8.0.0

"dependencies": {
    "@angular/animations": "~11.2.13",
    "@angular/cdk": "^11.2.12",
    "@angular/common": "~11.2.13",
    "@angular/compiler": "~11.2.13",
    "@angular/core": "~11.2.13",
    "@angular/fire": "^6.1.4",
    "@angular/forms": "~11.2.13",
    "@angular/material": "^11.2.12",
    "@angular/platform-browser": "~11.2.13",
    "@angular/platform-browser-dynamic": "~11.2.13",
    "@angular/router": "~11.2.13",
    "@nativescript/angular": "~11.2.0",
    "@nativescript/core": "~8.0.5",
    "@nativescript/firebase": "^11.1.3",
    "@nativescript/theme": "~3.0.1",
    "@ngx-translate/core": "^13.0.0",
    "@ngx-translate/http-loader": "^6.0.0",
    "@schematics/angular": "^11.2.12",
    "@swimlane/ngx-charts": "^18.0.0",
    "core-js": "^3.12.1",
    "firebase": "^8.6.0",
    "firebase-tools": "^9.10.2",
    "nativescript-gif": "^5.0.0",
    "nativescript-intl": "^4.0.2",
    "nativescript-sound": "^1.0.4",
    "nativescript-texttospeech": "^3.0.1",
    "nativescript-toasty": "^2.0.1",
    "nativescript-toasty-ns-7": "^14.0.0",
    "nativescript-ui-chart": "^8.0.2",
    "nativescript-ui-listview": "^9.1.0",
    "nativescript-ui-sidedrawer": "9.0.3",
    "ngx-custom-validators": "^11.0.1",
    "node-gyp": "^8.0.0",
    "npm-check-updates": "^11.5.11",
    "reflect-metadata": "~0.1.13",
    "rxjs": "~7.0.1",
    "tslib": "2.2.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1102.12",
    "@angular/cli": "~11.2.12",
    "@angular/compiler-cli": "~11.2.13",
    "@nativescript/android": "8.0.0",
    "@nativescript/schematics": "^11.2.0",
    "@nativescript/tslint-rules": "~0.0.5",
    "@nativescript/types": "~8.0.1",
    "@nativescript/webpack": "~5.0.0-beta.0ns",
    "@types/jasmine": "~3.7.2",
    "@types/jasminewd2": "~2.0.9",
    "@types/node": "^15.0.2",
    "codelyzer": "^6.0.2",
    "jasmine-core": "~3.7.1",
    "jasmine-spec-reporter": "~7.0.0",
    "karma": "~6.3.2",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~3.0.3",
    "karma-jasmine": "~4.0.1",
    "karma-jasmine-html-reporter": "^1.6.0",
    "nativescript-dev-typescript": "~0.10.0",
    "protractor": "~7.0.0",
    "sass": "^1.32.12",
    "ts-node": "~9.1.1",
    "tslint": "~6.1.3",
    "typescript": "~4.1.5"
  }

Describe the bug I'm trying to migrate my app to ns 8 to use webpack 5 and stuffs like RootLayout, When ns migrate is completed there is no webpack.config.js (has beed removed during the migration). So an error exists:

Preparing project... Found peer TypeScript 4.1.5

The webpack configuration file C:\Projekty\voclick.com\webpack.config.js does not exist. Ensure the file exists, or update the path in nativescript.config.(js|ts).

So I created a file with

const webpack = require('@nativescript/webpack')

module.exports = env => {
  webpack.init(env)

  return webpack.resolveConfig()
}

After this, now I have:

Error: Cannot find module '@ngtools/webpack'
Require stack:
- C:\Projekty\myapp\node_modules\@nativescript\webpack\dist\configuration\angular.js
- C:\Projekty\myapp\node_modules\@nativescript\webpack\dist\configuration\index.js
- C:\Projekty\myapp\node_modules\@nativescript\webpack\dist\index.js
- C:\Projekty\myapp\webpack.config.js
- C:\Projekty\myapp\node_modules\@nativescript\webpack\dist\bin\index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at getAngularCompilerPlugin (C:\Projekty\myapp\node_modules\@nativescript\webpack\dist\configuration\angular.js:139:39)
    at default_1 (C:\Projekty\myapp\node_modules\@nativescript\webpack\dist\configuration\angular.js:76:35)
    at C:\Projekty\myapp\node_modules\@nativescript\webpack\dist\index.js:128:13
    at Array.forEach (<anonymous>)
    at resolveChainableConfig (C:\Projekty\myapp\node_modules\@nativescript\webpack\dist\index.js:126:10)
    at Object.resolveConfig (C:\Projekty\myapp\node_modules\@nativescript\webpack\dist\index.js:155:42)
    at module.exports (C:\Projekty\myapp\webpack.config.js:6:18)
    at Command.<anonymous> (C:\Projekty\myapp\node_modules\@nativescript\webpack\dist\bin\index.js:60:44)
    at Command.listener [as _actionHandler] (C:\Projekty\myapp\node_modules\@nativescript\webpack\node_modules\commander\index.js:922:31)
    at Command._parseCommand (C:\Projekty\myapp\node_modules\@nativescript\webpack\node_modules\commander\index.js:1503:14)
    at Command._dispatchSubcommand (C:\Projekty\myapp\node_modules\@nativescript\webpack\node_modules\commander\index.js:1443:18)
    at Command._parseCommand (C:\Projekty\myapp\node_modules\@nativescript\webpack\node_modules\commander\index.js:1460:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Projekty\\myapp\\node_modules\\@nativescript\\webpack\\dist\\configuration\\angular.js',
    'C:\\Projekty\\myapp\\node_modules\\@nativescript\\webpack\\dist\\configuration\\index.js',
    'C:\\Projekty\\myapp\\node_modules\\@nativescript\\webpack\\dist\\index.js',
    'C:\\Projekty\\myapp\\webpack.config.js',
    'C:\\Projekty\\myapp\\node_modules\\@nativescript\\webpack\\dist\\bin\\index.js'
  ]
}
No configuration!
Executing webpack failed with exit code 0.

Do I need to install @ngtools/webpack, or modify webpack file somehow?

edusperoni commented 3 years ago

You can install @ngtools/webpack as a devDependency at the same version as your @angular/core