【发布时间】:2018-06-13 09:31:52
【问题描述】:
我正在尝试导入以下组件:https://github.com/airbnb/rheostat。
不幸的是,它试图导入 JSX 文件而不是编译的 ES5 组件,这会导致以下错误:
Module parse failed: /Users/sean/development/platform/node_modules/rheostat/src/Slider.jsx Unexpected token (34:11)
You may need an appropriate loader to handle this file type.
我能够在存储库here 中找到相关问题,但答案有点神秘。我用干净的create-react-app 设置尝试了同样的方法,效果很好。
我在这里遗漏了什么吗?正如您在我的 webpack 配置中看到的那样,我只转换了一个文件夹和两个扩展,这意味着我希望从 node_modules 导入 ES5 组件,而不是任何需要 babel 处理的东西。
包.json
"babel": {
"presets": [ "react", "es2015", "stage-0" ],
"env": {
"development": {
"presets": ["react-hmre"]
}
}
}
网页包
module: {
loaders: [{
test: /\.jsx?$/,
loader: 'babel-loader',
include: [
path.resolve(__dirname + "/../../react")
],
exclude: /node_modules/
},
【问题讨论】:
-
试试
import Rheostat from 'rheostat/lib';