let {name, age = 18} = { name: "xxx", age: 28}console.log(name, age)报错 =>i 「wds」: Project is running at http://localhost:8080/i 「wds」: webp_yarn core-js">
当前位置:   article > 正文

配置corejs版本问题解决_yarn core-js

yarn core-js

自己写的脚手架工具 npm i -g xd-es-cli
报错 =>
直接使用@babel/core

    "@babel/core": "^7.12.3",
  • 1

执行如下代码报错 =>

let {name, age = 18} = {
    name: "xxx",
    age: 28
}
console.log(name, age)
  • 1
  • 2
  • 3
  • 4
  • 5

报错 =>

i 「wds」: Project is running at http://localhost:8080/
i 「wds」: webpack output is served from undefined
i 「wds」: Content not from webpack is served from H:\ld\task\code\ECMScript\mk02\es-demo

WARNING: We noticed you're using the `useBuiltIns` option without declaring a core-js version. Currently, we assume version 2.x when no version is passed. Since this default version will likely change in future versions of Babel, we recommend explicitly setting the core-js version you are using via the `corejs` option.

You should also be sure that the version you pass to the `corejs` option matches the version specified in your `package.json`'s `dependencies` section. If it doesn't, you need to run one of the following commands:

  npm install --save core-js@2    npm install --save core-js@3
  yarn add core-js@2              yarn add core-js@3

(node:17604) [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future, all modifications are deprecated.
BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
        Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
        Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.
(Use `node --trace-deprecation ...` to show where the warning was created)
× 「wdm」: assets by path static/ 15.1 KiB
  asset static/favicon.ico 13.3 KiB [emitted] [from: static/favicon.ico] [copied]
  asset static/1-1.js 1.07 KiB [emitted] [from: static/1-1.js] [copied]
  asset static/1-2.js 750 bytes [emitted] [from: static/1-2.js] [copied]
asset index.js 896 KiB [emitted] (name: main)
asset index.html 310 bytes [emitted]
runtime modules 704 bytes 4 modules
modules by path ./node_modules/ 330 KiB
  modules by path ./node_modules/webpack-dev-server/client/ 20.9 KiB 10 modules
  modules by path ./node_modules/html-entities/lib/*.js 57.9 KiB 4 modules
  modules by path ./node_modules/webpack/hot/ 1.58 KiB 3 modules
  modules by path ./node_modules/url/ 37.4 KiB 3 modules
  modules by path ./node_modules/querystring/*.js 4.51 KiB
    ./node_modules/querystring/index.js 127 bytes [built] [code generated]
    ./node_modules/querystring/decode.js 2.34 KiB [built] [code generated]
    ./node_modules/querystring/encode.js 2.04 KiB [built] [code generated]
modules by path ./src/*.js 1.34 KiB
  ./src/index.js 98 bytes [built] [code generated]
  ./src/1-3.js 1.25 KiB [built] [code generated]

ERROR in ./src/1-3.js 1:0-43
Module not found: Error: Can't resolve 'core-js/modules/es6.function.name' 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 1888 ms
i 「wdm」: Failed to compile.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42

参考 => https://github.com/nuxt/nuxt.js/issues/5287
图片描述
修改corejs版本

"plugin": [
  ["@babel/plugin-transform-runtime", {
  "corejs":2
}]
]
  • 1
  • 2
  • 3
  • 4
  • 5

报错

i 「wds」: Project is running at http://localhost:8080/
i 「wds」: webpack output is served from undefined
i 「wds」: Content not from webpack is served from H:\ld\task\code\ECMScript\mk02\es-demo

WARNING: We noticed you're using the `useBuiltIns` option without declaring a core-js version. Currently, we assume version 2.x when no version is passed. Since this default version will likely change in future versions of Babel, we recommend explicitly setting the core-js version you are using via the `corejs` option.

You should also be sure that the version you pass to the `corejs` option matches the version specified in your `package.json`'s `dependencies` section. If it doesn't, you need to run one of the following commands:

  npm install --save core-js@2    npm install --save core-js@3
  yarn add core-js@2              yarn add core-js@3

(node:9088) [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future, all modifications are deprecated.
BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
        Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
        Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.
(Use `node --trace-deprecation ...` to show where the warning was created)
× 「wdm」: assets by path static/ 15.1 KiB
  asset static/favicon.ico 13.3 KiB [emitted] [from: static/favicon.ico] [copied]
  asset static/1-1.js 1.07 KiB [emitted] [from: static/1-1.js] [copied]
  asset static/1-2.js 750 bytes [emitted] [from: static/1-2.js] [copied]
asset index.js 891 KiB [emitted] (name: main)
asset index.html 310 bytes [emitted]
runtime modules 430 bytes 3 modules
cacheable modules 330 KiB
  modules by path ./node_modules/webpack-dev-server/client/ 20.9 KiB 10 modules
  modules by path ./node_modules/html-entities/lib/*.js 57.9 KiB 4 modules
  modules by path ./node_modules/url/ 37.4 KiB 3 modules
  modules by path ./node_modules/querystring/*.js 4.51 KiB
    ./node_modules/querystring/index.js 127 bytes [built] [code generated]
    ./node_modules/querystring/decode.js 2.34 KiB [built] [code generated]
    ./node_modules/querystring/encode.js 2.04 KiB [built] [code generated]
  modules by path ./node_modules/webpack/hot/*.js 1.42 KiB
    ./node_modules/webpack/hot/emitter.js 75 bytes [built] [code generated]
    ./node_modules/webpack/hot/log.js 1.34 KiB [built] [code generated]
./node_modules/webpack/hot/ sync nonrecursive ^\.\/log$ 170 bytes [built] [code generated]

ERROR in ./src/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: [BABEL] H:\ld\task\code\ECMScript\mk02\es-demo\src\index.js: .corejs is not a valid Plugin property
- Maybe you meant to use
"plugin": [
  ["@babel/plugin-transform-runtime", {
  "corejs": 3
}]
]
To be a valid plugin, its name and options should be wrapped in a pair of brackets
    at H:\ld\task\code\ECMScript\mk02\es-demo\node_modules\@babel\core\lib\config\validation\plugins.js:65:42
    at Array.forEach (<anonymous>)
    at validatePluginObject (H:\ld\task\code\ECMScript\mk02\es-demo\node_modules\@babel\core\lib\config\validation\plugins.js:54:20)
    at H:\ld\task\code\ECMScript\mk02\es-demo\node_modules\@babel\core\lib\config\full.js:256:55
    at Generator.next (<anonymous>)
    at Function.<anonymous> (H:\ld\task\code\ECMScript\mk02\es-demo\node_modules\@babel\core\lib\gensync-utils\async.js:26:3)
    at Generator.next (<anonymous>)
    at step (H:\ld\task\code\ECMScript\mk02\es-demo\node_modules\gensync\index.js:261:32)
    at evaluateAsync (H:\ld\task\code\ECMScript\mk02\es-demo\node_modules\gensync\index.js:291:5)
    at Function.errback (H:\ld\task\code\ECMScript\mk02\es-demo\node_modules\gensync\index.js:113:7)

webpack 5.4.0 compiled with 1 error in 1773 ms
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58

参考 => https://github.com/babel/babel/issues/8451
图片描述
正确配置方式 =>
es-demo\build\webpack.base.config.js

    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: 2 } // 指定 runtime-corejs 的版本,目前有 2 3 两个版本
                        }
                    ]]
                }
            }
        }]
    },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/625041
推荐阅读
相关标签
  

闽ICP备14008679号