laravel-mix / laravel-mix

The power of webpack, distilled for the rest of us.
MIT License
5.26k stars 806 forks source link

Problem with the webpack.config.js path in TCC shell (Windows) #3212

Open enigmatic-user opened 2 years ago

enigmatic-user commented 2 years ago

Description:

In the last few weeks, whenever I created a new project with Laravel Mix or when I installed it into an existing one, running npm run dev (or one of the other scripts starting Mix) just lead to the output

dev npm run development

development mix

Otherwise nothing happened. Now I found out that this only happens when I'm using the TCC shell (Take Command, see https://jpsoft.com/products/take-command.html); it works in Windows' CMD and PowerShell. After upgrading Take Command to the latest version (28), I finally got an error message:

[webpack-cli] Failed to load 'F:\xampp\htdocs\__test\_laravel-tests\laravel-9-reference\"node_modules\laravel-mix\setup\webpack.config.js"' config
[webpack-cli] Error: Cannot find module 'F:\xampp\htdocs\__test\_laravel-tests\laravel-9-reference\"node_modules\laravel-mix\setup\webpack.config.js"'
Require stack:
- F:\xampp\htdocs\__test\_laravel-tests\laravel-9-reference\node_modules\webpack-cli\lib\webpack-cli.js
- F:\xampp\htdocs\__test\_laravel-tests\laravel-9-reference\node_modules\webpack-cli\lib\bootstrap.js
- F:\xampp\htdocs\__test\_laravel-tests\laravel-9-reference\node_modules\webpack-cli\bin\cli.js
- F:\xampp\htdocs\__test\_laravel-tests\laravel-9-reference\node_modules\webpack\bin\webpack.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at WebpackCLI.tryRequireThenImport (F:\xampp\htdocs\__test\_laravel-tests\laravel-9-reference\node_modules\webpack-cli\lib\webpack-cli.js:244:16)
    at loadConfigByPath (F:\xampp\htdocs\__test\_laravel-tests\laravel-9-reference\node_modules\webpack-cli\lib\webpack-cli.js:1712:30)
    at F:\xampp\htdocs\__test\_laravel-tests\laravel-9-reference\node_modules\webpack-cli\lib\webpack-cli.js:1767:11
    at Array.map (<anonymous>)
    at WebpackCLI.loadConfig (F:\xampp\htdocs\__test\_laravel-tests\laravel-9-reference\node_modules\webpack-cli\lib\webpack-cli.js:1766:24)
    at WebpackCLI.createCompiler (F:\xampp\htdocs\__test\_laravel-tests\laravel-9-reference\node_modules\webpack-cli\lib\webpack-cli.js:2187:29) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'F:\\xampp\\htdocs\\__test\\_laravel-tests\\laravel-9-reference\\node_modules\\webpack-cli\\lib\\webpack-cli.js',
    'F:\\xampp\\htdocs\\__test\\_laravel-tests\\laravel-9-reference\\node_modules\\webpack-cli\\lib\\bootstrap.js',
    'F:\\xampp\\htdocs\\__test\\_laravel-tests\\laravel-9-reference\\node_modules\\webpack-cli\\bin\\cli.js',
    'F:\\xampp\\htdocs\\__test\\_laravel-tests\\laravel-9-reference\\node_modules\\webpack\\bin\\webpack.js'
  ]
}

In the first two lines of the error message you can see that there are double quotes in the path. The other shells seem to be more forgiving about this, but TCC stumbles upon it. Nevertheless I wouldn't say it's TCC's fault: While it's important to put a complete path in quotes in Windows, I don't think it's correct to have quotes in the middle of a path (although I'm not completely sure about it).

The problem is caused by line 75 of the node_modules/laravel-mix/bin/cli.js:

    `--config="${configPath}"`,

When I remove the double quotes here, everything works fine.

A few lines above, this can be found:

// We MUST use a relative path because the files
// created by npm dont correctly handle paths
// containg spaces on Windows (yarn does)
const configPath = path.relative(
    process.cwd(),
    require.resolve('../setup/webpack.config.js')
);

Well, if this is a relative path in each and every case, is there a chance it can contain spaces? I can't think of such a case. Then the quotes shouldn't be necessary and can safely be removed.

Steps To Reproduce:

Now the error message should show up.

thecrypticace commented 2 years ago

Thanks for the report. This hasn't changed in months so there's no real reason it should've just started showing up but the handling here is definitely suboptimal and has been on my list to investigate for a while.

I'm going to be working on Mix some this weekend so I'll take some time to look into this further. Thanks for the report!

enigmatic-user commented 2 years ago

Thanks for the quick reply!

Yes, I'm puzzled myself why this is a problem now whenever I add Laravel Mix. In older projects I modified the scripts section of the package.json like this:

    "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": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch-poll": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --watch-poll --progress --config=node_modules/laravel-mix/setup/webpack.config.js",
        "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": "mix --production"
    },

This worked fine, but even with these modifications I had no luck now. In one project I somehow got it to work, but TBH I have no idea how... ;-)

The proposed little change on the other hand solved all problems, and I even don't have to modify the scripts section anymore.

Thank you very much for looking into this!

enigmatic-user commented 2 years ago

@thecrypticace Did you have the opportunity to take a look at this? It's quite disturbing (although I have to admit that there probably aren't many people using this on a TCC console on Windows).

thecrypticace commented 2 years ago

Didn't get a chance to look at this one specifically sorry but I've got one other fairly important issue to look at this weekend so I'll add this to my list. Sorry for the wait!

enigmatic-user commented 2 years ago

There are a lot of updates recently, is there a chance that someone will take a look at this? That would be great, thanks!