从babel6切换到babel7的问题:属性名预期为字符串类型,但在Array.forEach()处为空。

问题描述 投票:0回答:1

我刚刚更新了Babel6到Babel7的所有必要的包,但无法解决如何使 babel.config.js 正确地得到一个或另一个错误,这取决于指定的 Babel7 插件。下面是我的 babel.config.js 的样子。

module.exports = {    
  "env": {
      "test": {
        "presets": [
          "@babel/preset-env",
          "@babel/preset-react"
        ],  
        "plugins": [
          "@babel/plugin-proposal-class-properties",
          "@babel/plugin-transform-modules-commonjs",
          "@babel/plugin-syntax-dynamic-import",
          "babel-plugin-dynamic-import-node",
          "@babel/plugin-proposal-export-default-from"
        ]   
      }   
    },  
    "plugins": [
      "@babel/plugin-transform-modules-commonjs",
      "@babel/plugin-proposal-export-default-from",
      "babel-plugin-dynamic-import-node",
      "@babel/plugin-transform-runtime",
      "@babel/plugin-transform-regenerator",
      "@babel/plugin-syntax-dynamic-import",
      [   
        "@babel/plugin-proposal-decorators",
        {   
          "legacy": true
        }   
      ],  
      "@babel/plugin-proposal-object-rest-spread",
      "@babel/plugin-proposal-class-properties",
      [   
        "babel-plugin-styled-components",
        {   
          "displayName": true
        }   
      ],  
      [   
        "babel-plugin-module-resolver",
        {   
          "root": [
            "./"
          ],  
          "extensions": [
            ".js",
            ".jsx",
            ".css"
          ],
          "alias": {
            "shared": "./shared/",
            "pages": "./pages/",
            "gtex-d3": "./node_modules/gtex-d3/"
          }
        }
      ]
    ],
    "presets": [
      "@babel/preset-react",
      [
        "@babel/preset-env",
        {
          "modules": false
        }
      ]
    ]
}

所以,在这样的配置下,我得到的错误是:

TypeError: (0 , _typeof2.default) is not a function: (0 , _typeof2.default) 不是一个函数。

在这里我找到了一个可能的解决方案。

https:/github.comzeitnext.jsissues6879

移除 "@babel/preset-env". 所以,在删除它之后,我在其中的一个 node_modules 包(这可能意味着 @babel/preset-env 是需要避免的...)。)

.node_modulesigvdistigv.esm.js 模块构建失败。TypeError.UsersvlasenkonaDesktopgris-seqr2uinode_model.js UsersvlasenkonaDesktopgris-seqr2uinode_modulesigvdistigv.esm.js。属性名预期类型为字符串,但在Array.forEach()处得到空值。

如果我去掉 "@babel/plugin-transform-modules-commonjs" 相反,我将得到另一个错误。

.node_modulessemantic-ui-reactdistesmodulesDropdownDropdown.js 1002:14-23 "export 'default'(导入为'PropTypes')在'prop-types'中找不到。

发生这种情况是因为被移除的 @babel/plugin-transform-modules-commonjs 是需要这样做的。所以,从这些 3 错误,在我看来,第二种应该是固定的,有一个线程。

https:/github.comalanbsmithbabel-plugin-react-add-propertyissues3。

而且还没有解决,所以我被卡住了。如果有任何建议,我将非常感激。

redux babel
1个回答
1
投票
  1. npm install --save-dev @babel/plugin-transform-destructuring
  2. . babelrc { "plugins": [ ["@babel/plugin-transform-destructuring", { "useBuiltIns": true }] ] }
© www.soinside.com 2019 - 2024. All rights reserved.