在webpack配置上接收意外的令牌

时间:2018-06-13 13:57:48

标签: python django reactjs webpack

我正在构建一个Web应用程序,并希望实现webpack以便同时运行react和django。当我尝试运行" webpack --config webpack.config.js "我收到堆栈跟踪中显示的以下错误。看起来这可能是一个微不足道的问题,但是我似乎无法确定问题的根源以便进行调试。

完整堆栈跟踪

SyntaxError: Unexpected token )
    at NativeCompileCache._moduleCompile (.\node_modules\v8-compile-cache\v8-compile-cache.js:226:18)
    at Module._compile (.\node_modules\v8-compile-cache\v8-compile-cache.js:172:36)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (.\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
    at WEBPACK_OPTIONS (.\node_modules\webpack-cli\bin\convert-argv.js:133:13)
    at requireConfig (.\node_modules\webpack-cli\bin\convert-argv.js:135:6)
    at .\node_modules\webpack-cli\bin\convert-argv.js:142:17
    at Array.forEach (<anonymous>)
    at module.exports (.\node_modules\webpack-cli\bin\convert-argv.js:140:15)
    at yargs.parse (.\node_modules\webpack-cli\bin\cli.js:241:39)
    at Object.parse (.\node_modules\yargs\yargs.js:552:18)
    at .\node_modules\webpack-cli\bin\cli.js:219:8
    at Object.<anonymous> (.\node_modules\webpack-cli\bin\cli.js:530:3)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at module.exports.filename (.\AppData\Roaming\npm\node_modules\webpack-cli\node_modules\import-local\index.js:16:66)
    at .\AppData\Roaming\npm\node_modules\webpack-cli\bin\cli.js:13:6
    at Object.<anonymous> (.\AppData\Roaming\npm\node_modules\webpack-cli\bin\cli.js:530:3)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)

ADDED WEBPACK CONFIG:

var path = require("path")
var webpack = require('webpack')
var BundleTracker = require('webpack-bundle-tracker')

module.exports = {
  context: __dirname,

  entry: './frontend/src/index.js', // entry point of our app. assets/js/index.js should require other js modules and dependencies it needs

  output: {
      path: path.resolve('./assets/bundles/'),
      filename: "[name]-[hash].js",
  },

  plugins: [
    new BundleTracker({filename: './webpack-stats.json'}),
  ],

  module: {
    loaders: {
      test: /\.jsx$|\.js$/,
      loaders: ['babel-loader'],
      include: path.resolve(__dirname, '../src')
    },

  resolve: {
    modulesDirectories: ['node_modules', 'bower_components'],
    extensions: ['', '.js', '.jsx']
  },
}

2 个答案:

答案 0 :(得分:2)

正如我所料,你只是忘了在你的配置上关闭一些大括号。

var path = require("path")
var webpack = require('webpack')
var BundleTracker = require('webpack-bundle-tracker')

module.exports = {
  context: __dirname,

  entry: './frontend/src/index.js', // entry point of our app. assets/js/index.js should require other js modules and dependencies it needs

  output: {
      path: path.resolve('./assets/bundles/'),
      filename: "[name]-[hash].js",
  },

  plugins: [
    new BundleTracker({filename: './webpack-stats.json'}),
  ],

    module: {
        loaders: {
            test: /\.jsx$|\.js$/,
            loaders: ['babel-loader'],
            include: path.resolve(__dirname, '../src')
        },
    },

  resolve: {
    modulesDirectories: ['node_modules', 'bower_components'],
    extensions: ['', '.js', '.jsx']
  }
}

答案 1 :(得分:0)

您忘记关闭模块属性:

module: {
  loaders: {
    test: /\.jsx$|\.js$/,
    loaders: ['babel-loader'],
    include: path.resolve(__dirname, '../src')
  },
},

注意最后一个大括号。