问题:报错webpack < 5 used to include polyfills for node.js core modules by default.

830 阅读1分钟

项目引入antd@1.5.1时提示

webpack < 5 used to include polyfills for node.js core modules by default.

webpack5中移除了nodejs核心模块的polyfill自动引入,所以需要手动引入,如果打包过程中有使用到nodejs核心模块,webpack会提示进行相应配置 解决

  1. 安装 yarn add node-polyfill-webpack-plugin
  2. 修改vue.config
    原来的config
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true
})

修改后的config

const { defineConfig } = require('@vue/cli-service')
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
module.exports = defineConfig({
  transpileDependencies: true,
  configureWebpack: {
    plugins: [new NodePolyfillPlugin()]
  }
})
  1. 正常运行