Good morning folks,
I have created a new project
laravel new app-test
Then I run as usual
composer install
npm install
And since I ain't a big fan of the new Laravel Vite, I followed the guide as I used to, in order to go back to Mix from Vite.
Migrating from Vite to Laravel Mix
Unfortunately this time something must be either or left behind or went wrong because when I run
npm install
I got this error message:
[webpack-cli] Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Workspace\PHP\badgamers\webpack.mix.js from C:\Workspace\PHP\badgamers\node_modules\laravel-mix\setup\webpack.config.js not supported.
webpack.mix.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename webpack.mix.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in C:\Workspace\PHP\badgamers\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
at module.exports (C:\Workspace\PHP\badgamers\node_modules\laravel-mix\setup\webpack.config.js:11:5)
at loadConfigByPath (C:\Workspace\PHP\badgamers\node_modules\webpack-cli\lib\webpack-cli.js:1439:37)
at async Promise.all (index 0)
at async WebpackCLI.loadConfig (C:\Workspace\PHP\badgamers\node_modules\webpack-cli\lib\webpack-cli.js:1454:35)
at async WebpackCLI.createCompiler (C:\Workspace\PHP\badgamers\node_modules\webpack-cli\lib\webpack-cli.js:1785:22)
at async WebpackCLI.runWebpack (C:\Workspace\PHP\badgamers\node_modules\webpack-cli\lib\webpack-cli.js:1890:20)
at async Command.<anonymous> (C:\Workspace\PHP\badgamers\node_modules\webpack-cli\lib\webpack-cli.js:912:21)
at async Promise.all (index 1)
at async Command.<anonymous> (C:\Workspace\PHP\badgamers\node_modules\webpack-cli\lib\webpack-cli.js:1372:13) {
code: 'ERR_REQUIRE_ESM'
}
Which make sense, but since this is not the first time I create a laravel project and move from Vite to Mix, and this is the very first time I had this error.
I'm sure that can be related on something I missed but right now I've spent quite some time completely clueless.
If you guys have experienced and solved the same issue would much appreciated a help.
Kind regards