Issue #2621 does not address the problem on Windows. While quoting is technically the correct solution, having node.js spawn a process with parameters containing spaces will not pass them correctly to the underlying process as quotes are being removed.
While someone came up with a quirky workaround, I think it would likely be preferable to have the webpack config file be passed with a relative path instead if applicable by defining let config = require.resolve('../setup/webpack.config.js'); and then passing the config as such: "${config.substr(config.startsWith(process.cwd()) ? process.cwd().length + 1 : 0)}"
It's certainly not a perfect solution, but it would address the most common error scenario on Windows, while not causing OS-specific bloat where it doesn't belong.
Run mix on Windows while having the project reside in a path containing one or more spaces.
Sorry, but I tried out both the latest npm version of laravel-mix (supposedly 6.0.5) and the current master branch. Both of which still observe the same error when using a setup with standard installation paths. What change is supposed to address this problem?
Failure to launch:
"C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" run watch-poll --scripts-prepend-node-path=auto
> @ watch-poll C:\Program Files\Apache\htdocs\xxxxx
> mix watch -- --watch-options-poll=1000
[webpack-cli] Running multiple commands at the same time is not possible
[webpack-cli] Found commands: 'bundle', 'Files\Apache\htdocs\xxxxx\node_modules\laravel-mix\setup\webpack.config.js'
[webpack-cli] Run 'webpack --help' to see available commands and options
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ watch-poll: `mix watch -- --watch-options-poll=1000`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the @ watch-poll script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\---\AppData\Roaming\npm-cache\_logs\2020-12-28T21_07_36_665Z-debug.log
Process finished with exit code 2
For completeness the 2020-12-28T21_07_36_665Z-debug.log:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'watch-poll',
1 verbose cli '--scripts-prepend-node-path=auto'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prewatch-poll', 'watch-poll', 'postwatch-poll' ]
5 info lifecycle @~prewatch-poll: @
6 info lifecycle @~watch-poll: @
7 verbose lifecycle @~watch-poll: unsafe-perm in lifecycle true
8 verbose lifecycle @~watch-poll: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Program Files\Apache\htdocs\xxxxx\node_modules\.bin;C:\Python27\;C:\Python27\Scripts;C:\Program Files\ImageMagick-7.0.8-Q16;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\IDM Computer Solutions\UltraEdit;C:\ProgramData\ComposerSetup\bin;C:\Program Files\AMD\AMDuProf\bin;C:\Program Files\Calibre2\;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\TortoiseGit\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Geth;C:\Program Files (x86)\Gpg4win\..\GnuPG\bin;C:\Program Files\Inkscape\bin;C:\Program Files\Apache\php74;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Users\---\AppData\Local\JSONBuddy;C:\Users\---\AppData\Local\Microsoft\WindowsApps;C:\Users\---\AppData\Roaming\Composer\vendor\bin;C:\Users\---\AppData\Roaming\npm
9 verbose lifecycle @~watch-poll: CWD: C:\Program Files\Apache\htdocs\xxxxx
10 silly lifecycle @~watch-poll: Args: [ '/d /s /c', 'mix watch -- --watch-options-poll=1000' ]
11 silly lifecycle @~watch-poll: Returned: code: 2 signal: null
12 info lifecycle @~watch-poll: Failed to exec watch-poll script
13 verbose stack Error: @ watch-poll: `mix watch -- --watch-options-poll=1000`
13 verbose stack Exit status 2
13 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:315:20)
13 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:315:20)
13 verbose stack at maybeClose (internal/child_process.js:1048:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
14 verbose pkgid @
15 verbose cwd C:\Program Files\Apache\htdocs\xxxxx
16 verbose Windows_NT 10.0.19041
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "watch-poll" "--scripts-prepend-node-path=auto"
18 verbose node v14.15.1
19 verbose npm v6.14.10
20 error code ELIFECYCLE
21 error errno 2
22 error @ watch-poll: `mix watch -- --watch-options-poll=1000`
22 error Exit status 2
23 error Failed at the @ watch-poll script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 2, true ]
The most promising ticket for the underlying situation is this here: https://github.com/nodejs/node/issues/29532
But it has been lying dormant for over a year now.
@JeffreyWay Given that situation it is not sensible to just close this issue in laravel-mix. A lot of developers will run into this problem and waste their time when a simple one-line-fix can work around the problem altogether.
Yes, I confirm it is an issue.
I have a space in the account name of the windows system, and not works.
"C:\Users\FirstName LastName\"
The workaround I found is updating the package.json with Laravel 7.x's scripts:
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --config=node_modules/laravel-mix/setup/webpack.config.js"
},
This seems to be working right now.
Unfortunately, it does not work.
It seems now.......
$ npm run prod
@ prod D:\Current Projects\practice-laravel
npm run production
@ production D:\Current Projects\practice-laravel
cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progres
s --config=node_modules/laravel-mix/setup/webpack.config.js
error: unknown option '--no-progress'
[webpack-cli] Run 'webpack --help' to see available commands and options
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ production: cross-env NODE_ENV=production node_modules/webpack/bin/w
ebpack.js --no-progress --config=node_modules/laravel-mix/setup/webpack.config.j
s
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the @ production script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\ASUS\AppData\Roaming\npm-cache_logs\2021-01-08T14_51_12_2
11Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ prod: npm run production
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the @ prod script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\ASUS\AppData\Roaming\npm-cache_logs\2021-01-08T14_51_12_4
81Z-debug.log
@Developer-Rezwan my bad, it only works for dev builds.
I could run prod builds but I had to downgrade to version 5.0.9, with Laravel 7's scripts. That works as expected, of course.
I guess we'll have to stick to that version until someone fixes this, or move the projects to any directory without spaces (bad solution)
Can I compile Vue-3 by laravel-mix 5.0.9?
Only in version 6 and above. But you could try kabbouchi/laravel-mix-vue3 for version 5.
Most helpful comment
The most promising ticket for the underlying situation is this here: https://github.com/nodejs/node/issues/29532
But it has been lying dormant for over a year now.
@JeffreyWay Given that situation it is not sensible to just close this issue in laravel-mix. A lot of developers will run into this problem and waste their time when a simple one-line-fix can work around the problem altogether.