Babel with NodeJS not working spread operator

问题: 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 : {...

问题:

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": "commonjs",
                "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?


回答1:

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

  • 发表于 2019-07-07 03:43
  • 阅读 ( 454 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除