[英]Getting build time error using webpack 5 and next js 12
This is our next.config.js file这是我们的 next.config.js 文件
const webpack = require('webpack');
// Initialize doteenv library
require('dotenv').config();
module.exports = {
swcMinify: true,
devIndicators: {
autoPrerender: false,
},
compiler: {
styledComponents: true, // ssr and displayName are configured by default
removeConsole: true,
},
webpack: (config) => {
config.plugins.push(new webpack.EnvironmentPlugin(process.env));
config.module.rules.push({
test: /\.svg$/,
issuer: {
and: [/\.(js|ts)x?$/],
},
use: ['@svgr/webpack'],
});
return config;
},
eslint: {
// Warning: Dangerously allow production builds to successfully complete even if
// your project has ESLint errors.
// but we are running eslint separately, therefore no need to worry about disabling
// ESLint on next build
ignoreDuringBuilds: true,
},
}
Getting this error/warning while building在构建时收到此错误/警告
DefinePlugin
Conflicting values for 'process.env.NEXT_RUNTIME'
Getting NEXT_RUNTIME: 'nodejs'
as value for process.env.NEXT_RUNTIME when I try to console.log当我尝试使用 console.log 时,获取
NEXT_RUNTIME: 'nodejs'
作为 process.env.NEXT_RUNTIME 的值
We are using SWC as the compiler instead of babel.我们使用 SWC 作为编译器而不是 babel。 Any idea how to fix this?
知道如何解决这个问题吗?
Replacing EnvironmentLogin
with DefinePlugin
fixed the warning for me.用
DefinePlugin
替换EnvironmentLogin
为我修复了警告。
I hope this helps 🤞我希望这会有所帮助🤞
webpack: (config, { dev, isServer }) => {
// ...
config.plugins.push(
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
}));
return config;
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.