Rails 5.2.1 Webpacker Babel无法转译React

时间:2018-09-21 23:35:22

标签: ruby-on-rails reactjs webpacker

环境宝石: 导轨5.2.1 Webpacker 3.5.5

这是我的package.json

{
  "private": true,
  "scripts": {
    "test": "jest",
    "build": "./bin/webpack"
  },
  "devDependencies": {
    "autoprefixer": "9.1.1",
    "jest": "23.4.1",
    "webpack-cli": "3.1.0",
    "webpack-dev-server": "2.11.2",
    "babel-core": "~6.26.3",
    "babel-loader": "^7.0.2",
    "babel-preset-react": "~6.24.1",
    "postcss-loader": "~3.0.0",
    "sass-loader": "~7.1.0",
    "webpack": "^3.5.5"
  },
  "jest": {
    "roots": [
      "app/specs/"
    ]
  },
  "dependencies": {
    "@rails/webpacker": "3.5",
    "prop-types": "~15.6.2",
    "react": "~16.5.2",
    "react-dom": "~16.5.2"
  }
}

webpacker.yml在.jsx部分接受extensions

这是我的.babelrc

{
  "presets": [
    [
      "env",
      {
        "modules": false,
        "targets": {
          "browsers": "> 1%",
          "uglify": true
        },
        "useBuiltIns": true
      }
    ],
    "react"
  ],
  "plugins": [
    "syntax-dynamic-import",
    "transform-object-rest-spread",
    [
      "transform-class-properties",
      {
        "spec": true
      }
    ]
  ]
}

我收到此错误,我想这意味着babel不会转嫁反应。

enter image description here

关于可能出什么问题的任何线索? 我刚刚开始使用webpacker并做出反应。 Webpacker可以正常工作,它可以注入所需的脚本或CSS。我安装了bundle exec rails webpacker:install:react的React,并使用hello_react.jsx

将示例文件<%= javascript_pack_tag 'hello_react' %>导入了我的一个视图中。

编辑: 这似乎是RAILS WEBPACKER问题,而不是babel问题。我尝试了所有可能重复的答案。请先正确阅读问题,然后再将其标记为重复。

0 个答案:

没有答案