这个错误出现在 webpack 中,target = node
但我已经完成target=web
(默认)
我也没有在外部加载 reactjs
在浏览器中加载应用程序时出现此错误
我做错了什么?
在控制台中
文件
webpack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const config = {
target: 'web',
externals: [nodeExternals()],
entry: './src/index.js',
output: {
filename: '[name].bundle.js',
path: __dirname + '/build'
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader"
})
},
{
test: /\.(png|svg|jpe?g|gif)$/,
use: [{
loader: 'file-loader',
options: {
name: '[path][name].[ext]'
}
}
]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: ['file-loader']
}
]
},
devtool: 'inline-source-map',
plugins: [
new HtmlWebpackPlugin({
title: 'Instarem.com'
})
]
};
module.exports = config;
.babelrc使用
babel-preset-env
{
"presets": [
"react",
[
"env",
{
"targets": {
"browsers": ["last 2 versions"]
},
"debug": true,
"modules": "commonjs"
}
]
],
"plugins": [
"transform-object-rest-spread",
"transform-class-properties"
]
}
谢谢 :)
我找到了线索
在 facebook 的create react 应用程序生成器包中,它显示
module.exports = __webpack_require__(/*! ./lib/React */ "./node_modules/react/lib/React.js");
但就我而言,它只显示
module.exports = require("react");