capacitor icon indicating copy to clipboard operation
capacitor copied to clipboard

build-nativescript.mjs can not find webpack.config.js on Windows

Open Ionaru opened this issue 1 year ago • 0 comments

When following the Nativescript for Capacitor installation instructions, the script npm run build:mobile (after fixing #28) errors with this message:

[webpack-cli] Failed to load 'C:\C:\Users\NAME\Projects\PROJECT\node_modules\@nativescript\capacitor\bridge\webpack.config.js' config
[webpack-cli] Error: Cannot find module 'C:\C:\Users\NAME\Projects\PROJECT\node_modules\@nativescript\capacitor\bridge\webpack.config.js'
Require stack:
- C:\Users\NAME\Projects\PROJECT\node_modules\webpack-cli\lib\webpack-cli.js
- C:\Users\NAME\Projects\PROJECT\node_modules\webpack-cli\lib\bootstrap.js
- C:\Users\NAME\Projects\PROJECT\node_modules\webpack-cli\bin\cli.js
- C:\Users\NAME\Projects\PROJECT\node_modules\webpack\bin\webpack.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at WebpackCLI.tryRequireThenImport (C:\Users\NAME\Projects\PROJECT\node_modules\webpack-cli\lib\webpack-cli.js:204:22)
    at loadConfigByPath (C:\Users\NAME\Projects\PROJECT\node_modules\webpack-cli\lib\webpack-cli.js:1404:38)
    at C:\Users\NAME\Projects\PROJECT\node_modules\webpack-cli\lib\webpack-cli.js:1454:88
    at Array.map (<anonymous>)
    at WebpackCLI.loadConfig (C:\Users\NAME\Projects\PROJECT\node_modules\webpack-cli\lib\webpack-cli.js:1454:68)
    at WebpackCLI.createCompiler (C:\Users\NAME\Projects\PROJECT\node_modules\webpack-cli\lib\webpack-cli.js:1785:33) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\NAME\\Projects\\PROJECT\\node_modules\\webpack-cli\\lib\\webpack-cli.js',
    'C:\\Users\\NAME\\Projects\\PROJECT\\node_modules\\webpack-cli\\lib\\bootstrap.js',
    'C:\\Users\\NAME\\Projects\\PROJECT\\node_modules\\webpack-cli\\bin\\cli.js',
    'C:\\Users\\NAME\\Projects\\PROJECT\\node_modules\\webpack\\bin\\webpack.js'
  ]
}
NativeScript build complete: undefined/nativescript/index.js

Note the double C:\C:\ in the pathname.

This is caused by this line: https://github.com/NativeScript/capacitor/blob/203b85f65af1c7e2a6bb16f3de2d369c9f4bda44/bin/build-nativescript.mjs#L77

It outputs

--config=/C:/Users/NAME/Projects/PROJECT/node_modules/@nativescript/capacitor/bridge/webpack.config.js

It should be possible to edit the above line to output the correct path on all platforms.

For example:

const cmdArgs = ['webpack', `--config=${fileURLToPath(url.toString())}`, ...args];

fileURLToPath from node:url should correctly turn the URL into a valid path.

Ionaru avatar Mar 27 '24 14:03 Ionaru