Webpack无法解析正则表达式

时间:2017-05-17 13:58:30

标签: webpack react-redux webpack-2

我正在使用webpack作为我的捆绑器处理React + Redux项目。初始一切正常但在我修改了一个快速服务器文件后,我收到以下错误消息。

SyntaxError: /Hidden/Xcodeer/path/webpack.config.js: Unexpected token 
(22:14)
  20 |     loaders:[
  21 |       {
> 22 |         test: /\.js$/,
     |               ^
  23 |         include: path.join(__dirname, 'client'),
  24 |         loaders: ['babel-loader']
  25 |       }
[nodemon] app crashed - waiting for file changes before starting...

这是我的webpack.config.js文件

import path from 'path';
import webpack from 'webpack';

export default {
  devtool: 'eval-source-map',
  entry: [
    'webpack-hot-middleware/client',
    path.join(__dirname, '/client/Index.jsx'),
  output: { 
    path: '/',
    filename: 'Bundle.js',
    publicPath: '/'
  },



watch: true,
  plugins [
    new webpack.NoErrorsPlugin(),
    new webpack.HotModuleReplacementPlugin()
  ],
  module: {
    loaders:[
      {
        test: /\.js$/,
        include: path.join(__dirname, 'client'),
        loaders: ['babel-loader']
      }
    ]
  },
  resolve: {
    extensions: ['.js', '.jsx']
  }
};

此外,这是我的package.json文件

{
  "name": "document-management-system",
  "version": "1.0.0",
  "description": "A full-stack document management system",
  "main": "client/Index.jsx",
  "scripts": {
    "start": "npm-run-all clean webpack",
    "start:dev": "npm-run-all clean webpack-dev-server",
    "clean": "rimraf ./client/public/build && mkdir client/public/build",
    "test": "mocha --autotest server/tests/**/*.js",
    "babel": "babel",
    "jade": "jade client/src/views/Index.jade -Po client/public",
    "jade:dev": "jade client/src/views/Index.jade -P -o client/public",
    "server": "nodemon --watch server --exec babel-node  -- server/Server.js",
    "webpack": "webpack -p babel-node",
    "jsdoc": "jsdoc server/ -r -c conf.json -d docs",
    "build": "webpack --config ./webpack.config.js --progress",
    "webpack-dev-server": "webpack-dev-server --progress --inline --open",
    "cover": "istanbul cover _mocha server/tests/**/*.js",
    "coveralls": "npm run cover -- --report lcovonly && cat ./coverage/lcov.info | coveralls"
  },
  "author": "Oluwafemi Akinwa",
  "repository": {
    "type": "git",
    "url": "https://github.com/andela-oakinwa/document-management-system"
  },
  "license": "MIT",
  "devDependencies": {
    "babel-cli": "^6.24.1",
    "babel-core": "^6.24.1",
    "babel-eslint": "^7.2.3",
    "babel-loader": "^6.4.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-node6": "^11.0.0",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "babel-preset-stage-1": "^6.24.1",
    "babel-register": "^6.24.1",
    "chai": "^3.5.0",
    "chai-http": "^3.0.0",
    "clean-webpack-plugin": "^0.1.16",
    "coveralls": "^2.13.1",
    "css-loader": "^0.28.0",
    "eslint": "^3.19.0",
    "eslint-config-airbnb": "^14.1.0",
    "eslint-loader": "^1.7.1",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^4.0.0",
    "eslint-plugin-react": "^6.10.3",
    "extract-text-webpack-plugin": "^2.1.0",
    "fs": "0.0.1-security",
    "istanbul": "^0.4.5",
    "jasmine-core": "^2.6.1",
    "karma": "^1.6.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-coverage": "^1.1.1",
    "karma-firefox-launcher": "^1.0.1",
    "karma-ie-launcher": "^1.0.0",
    "karma-jasmine": "^1.1.0",
    "karma-opera-launcher": "^1.0.0",
    "karma-safari-launcher": "^1.0.0",
    "karma-verbose-reporter": "0.0.6",
    "karma-webpack": "^2.0.3",
    "mocha": "^3.3.0",
    "mocha-lcov-reporter": "^1.3.0",
    "node-sass": "^4.5.2",
    "path": "^0.12.7",
    "rimraf": "^2.6.1",
    "sass-loader": "^6.0.3",
    "style-loader": "^0.16.1",
    "webpack-dev-server": "^2.4.5"
  },
  "dependencies": {
    "axios": "^0.16.1",
    "bcrypt-nodejs": "0.0.3",
    "body-parser": "^1.17.1",
    "dotenv": "^4.0.0",
    "express": "^4.15.2",
    "jade": "^1.11.0",
    "js-logger": "^1.3.0",
    "jsonwebtoken": "^7.4.0",
    "materialize-css": "^0.98.2",
    "morgan": "^1.8.1",
    "nodemon": "^1.11.0",
    "pg": "^6.1.5",
    "pg-hstore": "^2.3.2",
    "pug": "^2.0.0-rc.1",
    "react": "^15.5.4",
    "react-dom": "^15.5.4",
    "react-hot-loader": "^1.3.1",
    "react-materialize": "^0.18.4",
    "react-redux": "^5.0.4",
    "react-router": "^4.1.1",
    "redux": "^3.6.0",
    "sequelize": "^3.30.4",
    "sequelize-cli": "^2.7.0",
    "validator": "^7.0.0",
    "webpack": "^2.5.1",
    "webpack-dev-middleware": "^1.10.2",
    "webpack-hot-middleware": "^2.18.0"
  }
}

Webpack版本为2.4.1

我需要帮助,因为我的项目有一个艰难的截止日期。 感谢。

1 个答案:

答案 0 :(得分:1)

您忘记了]中的entry

  ...   
  entry: [
    'webpack-hot-middleware/client',
    path.join(__dirname, '/client/Index.jsx')
  ],
  output: { 
    path: '/',
    filename: 'Bundle.js',
    publicPath: '/'
  },
  ...