Error: Can‘t resolve ‘@babel/runtime-corejs2/helpers/slicedToArray‘

博主在使用corejs2编写自己的脚手架工具时遇到报错情况,还给出了参考链接https://github.com/nuxt/nuxt.js/issues/5287 ,反映了在开发过程中可能遇到的技术问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

自己写的脚手架工具 npm i -g xd-es-cli
我用的corejs2

function foo([a, b, c]) {
    console.log(a, b, c)
}
let arr = [1, 2, 3]
foo(arr)

报错 =>

× 「wdm」: assets by status 15.1 KiB [cached] 3 assets
asset index.js 895 KiB [emitted] (name: main)
cached modules 330 KiB [cached] 29 modules
runtime modules 704 bytes 4 modules
cacheable modules 1.56 KiB
  ./src/index.js 98 bytes [code generated]
  ./src/1-3.js 1.46 KiB [built] [code generated]

ERROR in ./src/1-3.js 1:0-74
Module not found: Error: Can't resolve '@babel/runtime-corejs2/helpers/slicedToArray' in 'H:\ld\task\code\ECMScript\mk02\es-demo\src'
 @ ./src/index.js 4:0-15

webpack 5.4.0 compiled with 1 error in 290 ms
i 「wdm」: Failed to compile.

参考 => https://github.com/nuxt/nuxt.js/issues/5287
图片描述

npm i core-js@3 @babel/runtime-corejs3

 module: {
        rules: [{
            test: /\.js$/,
            exclude: /node_modules/,
            use: {
                loader: 'babel-loader',
                options: {
                    presets: [
                        ['@babel/preset-env', {
                            "useBuiltIns": "usage"
                        }]
                    ],
                    plugins: [[
                        '@babel/plugin-transform-runtime',
                        {
                            corejs: { version: 3 } // 指定 runtime-corejs 的版本,目前有 2 3 两个版本
                        }
                    ]]
                }
            }
        }]
ERROR in ./node_modules/axios/lib/utils.js 3:0-146 Module not found: Error: Can't resolve 'D:/dp-project/callisto-h5/node_modules/@umijs/babel-preset-umi/node_modules/@babel/runtime/helpers/esm/slicedToArray' in 'D:\dp-project\callisto-h5\node_modules\axios\lib' Did you mean 'slicedToArray.js'? BREAKING CHANGE: The request 'D:/dp-project/callisto-h5/node_modules/@umijs/babel-preset-umi/node_modules/@babel/runtime/helpers/esm/slicedToArray' failed to resolve only because it was resolved as fully specified (probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"'). The extension in the request is mandatory for it to be fully specified. Add the extension to the request. @ ./node_modules/axios/lib/axios.js 3:0-31 32:2-14 36:2-14 74:24-40 @ ./node_modules/axios/index.js 1:0-35 5:12-23 6:17-33 7:20-39 8:15-29 9:18-35 10:14-27 11:10-19 12:13-25 13:19-37 14:13-25 15:17-33 16:19-37 17:21-41 18:17-33 19:17-33 20:18-35 21:0-208 @ ./src/utils/request.ts 2:0-26 111:9-14 @ ./src/utils/index.ts @ ./src/layouts/index.tsx @ ./src/.umi-production/core/routes.ts @ ./src/.umi-production/umi.ts 9:0-42 25:33-42 webpack compiled with 31 errors null build failed Error: build failed at D:\dp-project\callisto-h5\node_modules\@umijs\bundler-webpack\lib\index.js:172:29 at D:\dp-project\callisto-h5\node_modules\@umijs\deps\compiled\webpack\5\bundle5.js:114591:14 at processQueueWorker (D:\dp-project\callisto-h5\node_modules\@umijs\deps\compiled\webpack\5\bundle5.js:114529:6) at processTicksAndRejections (node:internal/process/task_queues:78:11) error Command failed with exit code 1.
最新发布
03-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值