chalk 5.x版本导致webpack打包backend报错

用Webpack打包Backend时报错,日志如下:

module.exports = require("chalk");
                 ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/yourname/Workspace/backend/node_modules/chalk/source/index.js from /Users/yourname/Workspace/backend/dist/app.js not supported.
Instead change the require of index.js in /Users/yourname/Workspace/backend/dist/app.js to a dynamic import() which is available in all CommonJS modules.
    at Object.chalk (/Users/yourname/Workspace/backend/dist/app.js:349:18)
    at __webpack_require__ (/Users/yourname/Workspace/backend/dist/app.js:533:41)
    at eval (webpack://rsg-backend/./src/logger/index.js?:9:63)
    at Object../src/logger/index.js (/Users/yourname/Workspace/backend/dist/app.js:139:1)
    at __webpack_require__ (/Users/yourname/Workspace/backend/dist/app.js:533:41)
    at eval (webpack://rsg-backend/./src/main.js?:20:74)
    at Object../src/main.js (/Users/yourname/Workspace/backend/dist/app.js:149:1)
    at __webpack_require__ (/Users/yourname/Workspace/backend/dist/app.js:533:41)
    at /Users/yourname/Workspace/backend/dist/app.js:585:37
    at Object.<anonymous> (/Users/yourname/Workspace/backend/dist/app.js:587:12) {
  code: 'ERR_REQUIRE_ESM'

查了一下是chalk升级到最新版本5.2.0,回退版本解决。

先remove

yarn remove chalk

然后再重新安装4.x最新版本。

yarn add chalk@^4.1.2
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值