我试图使用webpack与反应,但我收到此错误:
./app/main.js中的错误
Module parse failed: /Users/me/app/main.js Line 2: Unexpected token You may need an appropriate loader to handle this file type. | //npm | import React from 'react';
这是感兴趣的webpack配置部分:
test: /\.jsx?$/, include: path.join(__dirname, 'src'), loader: 'babel-loader', query: { presets: ['es2015', 'react']
和package.json:
"devDependencies": { "autoprefixer-loader": "^3.1.0", "babel-core": "^6.1.20", "babel-loader": "^6.1.0", "babel-preset-es2015": "^6.1.18", "babel-preset-react": "^6.1.18", "jest": "^0.1.40", "webpack": "^1.12.4", "webpack-dev-server": "^1.12.1", "css-loader": "^0.22.0", "style-loader": "^0.13.0" }, "dependencies": { "babel-polyfill": "^6.1.19", "history": "^1.17.0", "react": "^0.14.2", "react-dom": "^0.14.2", "react-mdl": "^1.0.4", "react-router": "^1.0.2" }
Felix Kling.. 6
查看错误消息中的路径
模块解析失败:/Users/me/app/main.js第2行:意外的令牌
似乎模块不在src
文件夹中.但是,您明确指出只有内部模块path.join(__dirname, 'src')
应该通过babel加载程序.
调整include
,使其也包括main.js
.
查看错误消息中的路径
模块解析失败:/Users/me/app/main.js第2行:意外的令牌
似乎模块不在src
文件夹中.但是,您明确指出只有内部模块path.join(__dirname, 'src')
应该通过babel加载程序.
调整include
,使其也包括main.js
.