【问题标题】:BABEL_TRANSFORM_ERROR. Property value expected type of string but got objectBABEL_TRANSFORM_ERROR。属性值期望字符串类型但得到对象
【发布时间】:2020-06-19 17:53:15
【问题描述】:

Screenshot of the error

我使用了本教程 https://www.vairix.com/tech-blog/server-side-rendering-ssr-of-create-react-app-cra-app-in-2020%C2%A0 和以下示例 github repo https://github.com/dariomac/poc-cra-ssr

我的 bootstrap.js,我使用 node.js v12 并在 Google 中尝试了所有可能的解决方案

require('ignore-styles');

require('@babel/register')({
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react"
  ],
  "plugins": [
    "@babel/plugin-proposal-class-properties",
    //"@babel/plugin-transform-modules-commonjs",
    [
      "transform-assets",
      {
        "extensions": [
          "css",
          "svg"
        ],
        "name": "static/media/[name].[hash:8].[ext]"
      }
    ]
  ]
});

require('./index');

注意:我已经在 bootstrap.js 的插件中添加了这个,因为 babel 抱怨了

  "plugins": [
    "@babel/plugin-proposal-class-properties",
    //"@babel/plugin-transform-modules-commonjs",

【问题讨论】:

    标签: javascript node.js babeljs ecmascript-5


    【解决方案1】:

    使用您的 bootstrap.js 代码,我在 Node v12.13.0 上没有遇到任何问题。

    我什至尝试了一个空且干净的 CRA 项目,它无需任何更改即可工作。我已将 Github 存储库的代码更新为每个依赖项的最新版本。

    请测试一下,如果解决了问题,请告诉我。

    【讨论】:

    猜你喜欢
    • 2017-11-02
    • 2020-03-11
    • 1970-01-01
    • 2018-02-07
    • 2016-10-03
    • 2019-02-09
    • 2018-02-19
    • 2021-10-24
    • 2020-06-28
    相关资源
    最近更新 更多