![](/img/trans.png)
[英]next.js error: Error: > Build failed because of webpack errors
[英]Getting build time error using webpack 5 and next js 12
这是我们的 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,
},
}
在构建时收到此错误/警告
DefinePlugin
Conflicting values for 'process.env.NEXT_RUNTIME'
当我尝试使用 console.log 时,获取NEXT_RUNTIME: 'nodejs'
作为 process.env.NEXT_RUNTIME 的值
我们使用 SWC 作为编译器而不是 babel。 知道如何解决这个问题吗?
用DefinePlugin
替换EnvironmentLogin
为我修复了警告。
我希望这会有所帮助🤞
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.