webpack打包后 运行错误 react is not defined

MOCHIKO
  • 310

萌新一枚,检查了很久自己也不知道是哪里错了了QAQ,
这是webpack.config.js

var path = require("path");
module.exports = {
    entry:'./app/index.js',
    output: {
        path: path.resolve(__dirname,'./dist'),
        filename: 'bundle.js'
    },
    module:{
        loaders: [
            {
                test:/\.js$/,
                exclude: /node_modules/,
                loader:"babel-loader",
                query:
                {
                    "presets": [
                        "react",
                        "es2015",
                    ]
                    
                }
            },
            {
                test:/\.css$/,
                loader: "style-loader!css-loader"
            },
            {
                test:/\.less/,
                loader:'style-loader!css-loader!less-loader'
            }
        ]
    }
}

然后是index.js

import React from 'react';
console.log(react.version);

wenpack的版本是3.0,打包的时候没有警告和报错,react版本是15.6.1,浏览器报错是:
图片描述

谢谢各位QAQ

回复
阅读 4.3k
2 个回答

大兄弟,你定义的变量叫React,react当然就是未定义咯,js变量是区分大小写的

console.log(React.version);

宣传栏