[英]webpack/babel/react - unexpected token error
I'm already using babel-preset-react
and babel-preset-es2015
. 我已经在使用
babel-preset-react
和babel-preset-es2015
。
package.json 的package.json
{
"name": "react-spring-demo",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.9.0",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.5.0",
"webpack": "^1.13.1"
},
"dependencies": {
"react": "^15.1.0"
}
}
webpack.config.js webpack.config.js
module.exports = {
entry: [
'./app/app.js'
],
module: {
loaders: [
{ test: /\.jsx?$/, include: __dirname + '/app', loader: "babel", query: { presets: ['es2015', 'react'] } }
]
},
output: {
filename: 'bundle.js',
path: __dirname + '/dist'
}
}
.babelrc .babelrc
{ "presets": ["es2015", "react"] }
I think I'm missing something very simple. 我想我缺少了一些简单的东西。 I've already tried a few things like using
./app
instead of __dirname + "/app"
and using .js$
instead of .jsx?$
. 我已经尝试了一些方法,例如使用
./app
代替__dirname + "/app"
以及使用.js$
代替.jsx?$
。 Also, you'll notice I'm using the latest versions of all the dependencies. 另外,您会注意到我正在使用所有依赖项的最新版本。 I've read numerous other posts about people having problems when updating to babel 6 because of a missing react preset.
我读过许多其他文章,内容涉及由于缺少反应预设而在更新至babel 6时遇到问题的人。 This seems to be something different.
这似乎有所不同。 Shouldn't these versions not have issues?
这些版本不应该没有问题吗? Thanks
谢谢
@Richard @Richard
ERROR in ./app/app.js
Module parse failed: C:\Users\vdixit\Desktop\react-spring-demo\src\main\resources\static\app\app.js Unexpected token (6:6)
You may need an appropriate loader to handle this file type.
Alright, I found a fix. 好吧,我找到了解决方法。 Apparently using the npm
path
module fixes this. 显然,使用npm
path
模块可以解决此问题。
Instead of: 代替:
include: __dirname + '/app'
I used: 我用了:
include: path.join(__dirname, '/app'),
Thanks! 谢谢!
Edit: I'm using windows for anyone else with this issue- but I read somewhere that this fix also works for mac 编辑:我正在将Windows用于此问题的任何其他人-但我在某处读到此修复程序也适用于mac
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.