Babel.js 使用webpack 5和next js 12获取构建时错误

62lalag4  于 2022-12-08  发布在  Babel
关注(0)|答案(1)|浏览(233)

这是我们的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。有什么办法可以解决这个问题吗?

sbdsn5lh

sbdsn5lh1#

EnvironmentLogin替换为DefinePlugin为我修复了警告。
我希望这能帮上忙🤞

webpack: (config, { dev, isServer }) => {
  // ...

  config.plugins.push(
    new webpack.DefinePlugin({
       'process.env.NODE_ENV': JSON.stringify(NODE_ENV) 
     }));

      return config;
    },

相关问题