My task is to upgrade package.json in Laravel.
I haven't had any problems using Laravel-Mix 5 ver until now, but when I run "yarn run", got the following error after switching to 6 ver.
[webpack-cli] Error: You must compile JS to extract vendor code at Extract.webpackEntry (/var/www/html/node_modules/laravel-mix/src/components/Extract.js:46:19) at /var/www/html/node_modules/laravel-mix/src/components/ComponentRegistrar.js:112:53 at /var/www/html/node_modules/laravel-mix/src/Dispatcher.js:39:62 at Array.map () at Dispatcher.fire (/var/www/html/node_modules/laravel-mix/src/Dispatcher.js:39:47) at Mix.dispatch (/var/www/html/node_modules/laravel-mix/src/Mix.js:248:32) at WebpackConfig.buildEntry (/var/www/html/node_modules/laravel-mix/src/builder/WebpackConfig.js:62:24) at WebpackConfig.build (/var/www/html/node_modules/laravel-mix/src/builder/WebpackConfig.js:27:20) at Mix.build (/var/www/html/node_modules/laravel-mix/src/Mix.js:89:35) at module.exports (/var/www/html/node_modules/laravel-mix/setup/webpack.config.js:16:16) error Command failed with exit code 2. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I support it's maybe due to webpack.mix.js.
The file is below.
※Partially modified.
const mix = require("laravel-mix");
const webpack = require("webpack");
const SentryWebpackPlugin = require("@sentry/webpack-plugin");
require("laravel-mix-react-typescript-extension");
require("laravel-mix-merge-manifest");
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
const additionalEnvPlugin = new webpack.DefinePlugin({
"process.env": {
APP_TYPE: JSON.stringify("admin"),
SENTRY_DSN: JSON.stringify(process.env.SENTRY_DSN),
DEVICE: JSON.stringify("pc"),
},
});
const isSentryActive =
process.env.SENTRY_DSN !== undefined && process.env.SENTRY_DSN !== "";
const sentryWebpackPlugin = new SentryWebpackPlugin({
dryRun: !isSentryActive,
setCommits: {
repo: "sample/sample-server",
commit: process.env.SENTRY_RELEASE,
},
deploy: {
env: process.env.MIX_ENV
},
include: "./public/pc/admin",
urlPrefix: `${process.env.SENTRY_APP_URL}/pc/admin/`,
release: process.env.SENTRY_RELEASE,
});
mix
.reactTypeScript(
"resources/react/pc/admin/chat/index.tsx",
"public/pc/admin/components/chat"
)
.extract(["react"], "public/pc/admin/components/chat/vendor.js")
.mergeManifest()
.sourceMaps(mix.inProduction(), "source-map")
.webpackConfig({
plugins: [additionalEnvPlugin, sentryWebpackPlugin],
});
if (mix.inProduction()) {
mix.version();
}
My env
- PHP: 7.4.29
- Laravel :8.76.2
- Yarn: 1.22.5
- Node: 16.14.2
- Laravel Mix: 6.0.43