【发布时间】:2017-12-11 22:42:13
【问题描述】:
我有一个项目需要使用 redux-websocket-autoreconnect
运行 webpack 时出现错误:
ERROR in ./~/redux-websocket-autoreconnect/src/index.js
Module parse failed: C:\workspaces\Engineering\projects\wcc\static\releaseBranches\25.X.X\src\clients\default\pmxd\node_modules\redux-websocket-autoreconnect\src\index.js Unexpected token (21:15)
You may need an appropriate loader to handle this file type.
| const createMiddleware = () => {
| // Hold a reference to the WebSocket instance in use.
| let websocket: ?WebSocket;
| let websocketConfig: ?Config
|
@ ./app/store/configure.store.jsx 40:35-75
@ ./app/app.jsx
@ multi babel-polyfill ./app/app.jsx
在 webpack.config.js 我有这个:
module: {
rules: [
{
loader: 'babel-loader',
query: {
presets: ['react', 'flow', 'es2015', 'stage-0'],
plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy'],
},
test: /\.jsx?$/,
exclude: /(node_modules|bower_components|WidgetLib|console)/
},
{
loader: 'babel-loader',
query: {
presets: ['flow', 'es2015', 'stage-0']
},
test: /node_modules\/redux-websocket-autoreconnect/
},....
我的猜测是错误显然是关于编译器无法识别 index.js 中的 es2015 代码,基本上是这样的:
const createMiddleware = () => {
// Hold a reference to the WebSocket instance in use.
let websocket: ?WebSocket;
let websocketConfig: ?Config
/**
* A function to create the WebSocket object and attach the standard callbacks
*/
const initialize = ({ dispatch }, config: Config) => {
// Instantiate the websocket.
websocket = createWebsocket(config);
websocketConfig = config
错误发生在 Windows 10 上。(在 Mac 上编译正常)
使用 webpack@2.7.0、redux@3.7.2、react@15.6.2
知道可能缺少什么吗?
谢谢!
【问题讨论】:
-
从 webpack 中移除带有
test: /node_modules\/redux-websocket-autoreconnect/的规则,该库已经被转译了。
标签: reactjs ecmascript-6 react-redux