javascript - Babel with NodeJS not working spread operator - Stack Overflow

I'm using Babel (7.5.0) and NodeJS latest (12.x), so the spread operator is already handled by Nod

I'm using Babel (7.5.0) and NodeJS latest (12.x), so the spread operator is already handled by NodeJS and I don't want babel to mess with it.

This is my .babelrc :

{
    "plugins": [
        "@babel/plugin-proposal-class-properties",
        "@babel/plugin-transform-runtime"
    ],
    "presets": [
        [
            "@babel/preset-env",
            {
                "modules": "monjs",
                "targets": {
                    "node": "current"
                },
                "useBuiltIns": "usage"
            }
        ]
    ]
}

This is my error :

ERROR in ./src/utils/logger/logger.js
Module build failed: ReferenceError: Unknown helper objectSpread2
    at loadHelper (/app/node_modules/@babel/helpers/lib/index.js:238:27)
    at Object.getDependencies (/app/node_modules/@babel/helpers/lib/index.js:279:21)
    at File.addHelper (/app/node_modules/@babel/core/lib/transformation/file/file.js:204:33)
    at PluginPass.addHelper (/app/node_modules/@babel/core/lib/transformation/plugin-pass.js:31:22)
    at PluginPass.ObjectExpression (/app/node_modules/@babel/plugin-proposal-object-rest-spread/lib/index.js:379:25)
    at newFn (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/visitors.js:193:21)
    at NodePath._call (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:88:12)
    at TraversalContext.visitQueue (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:118:16)
    at TraversalContext.visitMultiple (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:85:17)
    at TraversalContext.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:144:19)
    at Function.traverse.node (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/index.js:94:17)
    at NodePath.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:95:18)
    at TraversalContext.visitQueue (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:118:16)
    at TraversalContext.visitMultiple (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:85:17)
    at TraversalContext.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:144:19)
    at Function.traverse.node (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/index.js:94:17)
    at NodePath.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:95:18)
    at TraversalContext.visitQueue (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:118:16)
    at TraversalContext.visitSingle (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:90:19)
    at TraversalContext.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:146:19)
    at Function.traverse.node (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/index.js:94:17)
    at NodePath.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:95:18)
    at TraversalContext.visitQueue (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:118:16)
    at TraversalContext.visitMultiple (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:85:17)
    at TraversalContext.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:144:19)
    at Function.traverse.node (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/index.js:94:17)
    at NodePath.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:95:18)
    at TraversalContext.visitQueue (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:118:16)
 @ ./src/app.js 5:0-40
 @ multi ./src/app.js

I've read that I need to install some plugin, but I think that's for older nodejs versions, I don't see why I need a plugin for a feature built-in nodejs.

How can I do that?

Update:

I created an issue there :

I'm using Babel (7.5.0) and NodeJS latest (12.x), so the spread operator is already handled by NodeJS and I don't want babel to mess with it.

This is my .babelrc :

{
    "plugins": [
        "@babel/plugin-proposal-class-properties",
        "@babel/plugin-transform-runtime"
    ],
    "presets": [
        [
            "@babel/preset-env",
            {
                "modules": "monjs",
                "targets": {
                    "node": "current"
                },
                "useBuiltIns": "usage"
            }
        ]
    ]
}

This is my error :

ERROR in ./src/utils/logger/logger.js
Module build failed: ReferenceError: Unknown helper objectSpread2
    at loadHelper (/app/node_modules/@babel/helpers/lib/index.js:238:27)
    at Object.getDependencies (/app/node_modules/@babel/helpers/lib/index.js:279:21)
    at File.addHelper (/app/node_modules/@babel/core/lib/transformation/file/file.js:204:33)
    at PluginPass.addHelper (/app/node_modules/@babel/core/lib/transformation/plugin-pass.js:31:22)
    at PluginPass.ObjectExpression (/app/node_modules/@babel/plugin-proposal-object-rest-spread/lib/index.js:379:25)
    at newFn (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/visitors.js:193:21)
    at NodePath._call (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:88:12)
    at TraversalContext.visitQueue (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:118:16)
    at TraversalContext.visitMultiple (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:85:17)
    at TraversalContext.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:144:19)
    at Function.traverse.node (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/index.js:94:17)
    at NodePath.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:95:18)
    at TraversalContext.visitQueue (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:118:16)
    at TraversalContext.visitMultiple (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:85:17)
    at TraversalContext.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:144:19)
    at Function.traverse.node (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/index.js:94:17)
    at NodePath.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:95:18)
    at TraversalContext.visitQueue (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:118:16)
    at TraversalContext.visitSingle (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:90:19)
    at TraversalContext.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:146:19)
    at Function.traverse.node (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/index.js:94:17)
    at NodePath.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:95:18)
    at TraversalContext.visitQueue (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:118:16)
    at TraversalContext.visitMultiple (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:85:17)
    at TraversalContext.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:144:19)
    at Function.traverse.node (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/index.js:94:17)
    at NodePath.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:95:18)
    at TraversalContext.visitQueue (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:118:16)
 @ ./src/app.js 5:0-40
 @ multi ./src/app.js

I've read that I need to install some plugin, but I think that's for older nodejs versions, I don't see why I need a plugin for a feature built-in nodejs.

How can I do that?

Update:

I created an issue there : https://github./babel/babel-loader/issues/798

Share Improve this question edited Jul 9, 2019 at 9:59 HRK44 asked Jul 5, 2019 at 10:05 HRK44HRK44 2,7823 gold badges14 silver badges33 bronze badges 7
  • this plugin "transform-object-rest-spread" enables spread operator. I am not sure if some feature is already built in then why we have to use some plugin to use that feature. – Usama Tahir Commented Jul 5, 2019 at 10:09
  • 1 Do I have to use this plugin? Even with NodeJS 12.x ? – HRK44 Commented Jul 5, 2019 at 10:42
  • 1 I am not sure. I didn't check it. let me dig into it and I will add a ment about my findings here. – Usama Tahir Commented Jul 5, 2019 at 10:44
  • I can successfully use spread operator in node version v10.16.0. – Usama Tahir Commented Jul 5, 2019 at 10:52
  • So you mean that it does not work with Node v12.x but works fine with v10.16.0? – Bilal Commented Jul 5, 2019 at 13:55
 |  Show 2 more ments

1 Answer 1

Reset to default 7

Babel maintainer here.

We have a bug in v7.5.0 (it will soon be fixed in v7.5.1). You have two possible workaround:

  1. Run npm install @babel/helpers (or with yarn): this will force npm to download @babel/helpers v7.5.0, which contains the missing helper. If you are also using @babel/transform-runtime, make usre that @babel/runtime is v7.5.0
  2. If you are using yarn, you can lock @babel/plugin-proposal-object-rest-spread to an older version which isn't affected by the issue. Add this code to your package.json:

    "resolutions": {
      "**/@babel/plugin-proposal-object-rest-spread": "7.4.4"
    }
    

EDIT This should be fixed in v7.5.1, please update

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745579869a4634188.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信