跟踪:节点类型 SpreadProperty 已在 Object.isSpreadProperty 处重命名为 SpreadElement

IT技术 reactjs webpack babeljs
2021-04-13 03:31:43

我正在启动一个 React 应用程序,这是我的 Webpack 配置:

'use strict'

const ExtractPlugin = require('extract-text-webpack-plugin')
const HTMLPlugin = require('html-webpack-plugin')
module.exports = {
    devtool: 'eval',
    entry: `${__dirname}/src/main.js`,
    output: {
        filename: 'bundle-[hash].js',
        path: `${__dirname}/build`,
        publicPath: '/',
    },
    mode: 'development',
    performance: {
        hints: false
    },
    plugins: [
        new HTMLPlugin(),
        new ExtractPlugin('bundle-[hash].css'),
    ],
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_module/,
                loader: 'babel-loader',
            },
            {
                test: /\.scss$/,
                loader: ExtractPlugin.extract(['css-loader', 'sass-loader']),
            },
        ],
    },
}

然后,我有一个 package.json 文件,这里是依赖项:

"devDependencies": {
    "@babel/core": "^7.1.6",
    "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
    "@babel/preset-env": "^7.1.6",
    "@babel/preset-react": "^7.0.0",
    "and": "0.0.3",
    "babel-cli": "^6.26.0",
    "babel-core": "^7.0.0-bridge.0",
    "babel-loader": "^8.0.4",
    "eslint": "^5.9.0",
    "install": "^0.12.2",
    "jest": "^23.6.0",
    "npm": "^6.4.1",
    "webpack-cli": "^3.1.2"
  },
  "dependencies": {
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.7.0",
    "css-loader": "^1.0.1",
    "extract-text-webpack-plugin": "^4.0.0-beta.0",
    "html-webpack-plugin": "^3.2.0",
    "node-sass": "^4.11.0",
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "resolve-url-loader": "^3.0.0",
    "sass-loader": "^7.1.0",
    "webpack": "^4.25.1",
    "webpack-dev-server": "^3.1.10"
  } 

我已经尝试了很多方法将 babel 包更新到第 7 版,更改 babelrc 配置,无论如何。

该项目虽然编译,但在编译开始时我收到以下消息:

跟踪:节点类型 SpreadProperty 已在 Object.isSpreadProperty 处重命名为 SpreadElement

大约有一百行这样的。在打印出所有这些行之后,编译过程继续并成功完成。

那是什么,我怎样才能摆脱这些行?

5个回答

这是为我解决问题的最终设置。

.babelrc

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react"
  ],
  "plugins": [
    "@babel/plugin-proposal-object-rest-spread"
  ]
}

为了更好地理解,这是我的 package.json 的devDependencies

"devDependencies": {
    "@babel/core": "^7.1.6",
    "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
    "@babel/plugin-transform-object-assign": "^7.0.0",
    "@babel/plugin-transform-react-jsx": "^7.1.6",
    "@babel/preset-env": "^7.1.6",
    "@babel/preset-react": "^7.0.0",
    "babel-loader": "8.0.4",
    "prop-types": "15.6.2",
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "style-loader": "^0.23.1",
    "utils": "^0.3.1",
    "webpack": "4.26.1",
    "webpack-cli": "3.1.2",
    "webpack-dev-server": "^3.1.10"
  }

这是我的webpack.config.jsmodule部分:

module: {
        rules: [
            {
                test: /\.(js|jsx)$/ ,
                exclude: /node_modules/,
                loaders: "babel-loader"
            }
        ]
    }
不知道这不是被接受的答案,但这应该是它,我已经更新到 babel 7 但还没有使用正确的更新插件
2021-05-29 03:31:43

出现此问题是由于使用过时

`"babel-plugin-transform-object-rest-spread"`

在 package.json 中更新这个

`"@babel/plugin-proposal-object-rest-spread": "^7.0.0",`

并在我的情况下更新您的 .babelrc.js 文件,它看起来像这样

const isTest = String(process.env.NODE_ENV) === 'test'
module.exports = {
  presets: [["@babel/env", { modules: isTest ? 'commonjs' : false }, "@babel/react"]],
  plugins: [
    'syntax-dynamic-import',
    'transform-class-properties',
    '@babel/plugin-proposal-object-rest-spread',
  ],
}

这解决了我的问题

之前在我的 .babelrc

我正在使用插件: ["transform-object-rest-spread", { "useBuiltIns": true }],

然后我切换到它"@babel/plugin-proposal-object-rest-spread",所有这些警告都消失了,这非常好。`

是的,除了信息 - 我们可以在 .babelrc 或 package.json 中更改它,无论哪个文件已经有 babel 设置
2021-06-01 03:31:43

就我而言,我没有实现 Webpack 配置,但仍然存在错误。执行了这么多解决方案后,错误还是一样,或者一旦删除了错误又出现了另一个。最后,我删除了.bablerc,.babelrcpackage-lock.json文件rm -rf node_modules && npm install,然后运行然后运行react-native run-android,它对我有用。:-)

我相信问题来自使用 babel-preset-react-native,这取决于 /babel-plugin-transform-object-rest-spread(@babel/plugin-proposal-object-rest-spread 的旧版本)。而不是删除整个 .babelrc,您应该能够react-native从预设中删除
2021-06-11 03:31:43

如果这里没有任何效果,只需从旧 babel 中删除插件。在我的情况下,删除以下扩展插件已经消失了。

   plugins: ["transform-object-rest-spread"]