未捕获的ReferenceError:react未定义webpack

时间:2016-10-28 20:05:03

标签: javascript reactjs webpack

尝试加载我的应用时,我在浏览器控制台中收到以下错误消息。任何人都可以解释为什么没有找到反应?

Uncaught ReferenceError: react is not defined

我正在使用webpack捆绑我的代码。捆绑本身正在通过。

webpack config:

var path = require('path');
var webpack = require('webpack');

module.exports = {
  devtool: 'eval-source-map',
  entry: [
    path.join(__dirname, 'src/client/app.js'),
    path.join(__dirname, 'src/client/assets/styles/main.less')
  ],
  output: {
    path: path.join(__dirname, '/dist/'),
    filename: "bundle.js"
  },
  module: {
    loaders: [
      {
        test: /.jsx?$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        query: {
          presets: ['es2015', 'react', 'stage-2']
        }
      },
      {
        test: /\.json$/,
        loader: 'json-loader'
      },
      {
        test: /\.less$/,
        loader: "style!css!less"
      }
    ]
  },
  watch: true,
  node: {
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  },
  externals: /^[a-z\-0-9]+$/
};

由于

1 个答案:

答案 0 :(得分:-1)

尝试将此添加到您的webpack.config.js

externals: {
  "react": "React"
}

或者如果你使用ReactDOM:

externals: {
  "react": "React",
  "react-dom": "ReactDOM"
}