这发生在编译期间进行 require 调用时:
错误指向声明它的行:
var Module = require('module');
这是在 require-from-string 的 index.js 中实际上我可以将该 require 语句放在它继续导致错误的任何地方。
我已经使用 npm 安装了模块,并且它确实存在于我的 node_modules 中。
我的 webpack.config.js :
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack')
const standardOptions = require('./package.json').standard
const environment = process.env.NODE_ENV || 'development'
const $ = {}
const modulePattern = /(node_modules|bower_components)/
module.exports = {
node: {
fs: 'empty'
},
entry: './app/javascript/app.js',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'app.js'
},
plugins: [
// Copy our app's index.html to the build folder.
new CopyWebpackPlugin([
{ from: './app/index.html', to: "index.html" }
])
],
module: {
rules: [
{
test: /\.css$/,
use: [ 'style-loader', 'css-loader', "postcss-loader" ]
}
],
loaders: [
{ test: /\.json$/, use: 'json-loader' },
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['es2015'],
plugins: ['transform-runtime']
}
}
]
}
}