未在 webpack 中加载标准模块 Node.JS
Not loading standard module Node.JS in webpack
NodeJS 标准模块问题:url 模块、http、https、zlib、stream
我的设置文件:
webpack: {
custom: {
entry: './src/index.js',
output: {
path: 'build/',
filename: 'index.js'
},
target: 'node',
resolve: {
extensions: [
'.js',
],
root: '.'
},
module: {
loaders: [
{ test: /\.js$/, loader: 'jsx-loader' },
],
}
}
}
在 运行 构建并打开 index.html 之后,在控制台中看到错误:Uncaught ReferenceError: require is not defined
打开详情,查看:
function(module, exports) {
module.exports = require("url");
},
还有其他标准默认模块Node.JS:http、https、zlib、stream
要求不旋转。怎么固定的?
将目标 'node' 更改为 'web' (target: 'web'
)。如果使用 require('fs')
,则必须使用带有 brfs 的转换加载器:{ test: /\.js$/, loader: 'transform?brfs!}
NodeJS 标准模块问题:url 模块、http、https、zlib、stream 我的设置文件:
webpack: {
custom: {
entry: './src/index.js',
output: {
path: 'build/',
filename: 'index.js'
},
target: 'node',
resolve: {
extensions: [
'.js',
],
root: '.'
},
module: {
loaders: [
{ test: /\.js$/, loader: 'jsx-loader' },
],
}
}
}
在 运行 构建并打开 index.html 之后,在控制台中看到错误:Uncaught ReferenceError: require is not defined 打开详情,查看:
function(module, exports) {
module.exports = require("url");
},
还有其他标准默认模块Node.JS:http、https、zlib、stream
要求不旋转。怎么固定的?
将目标 'node' 更改为 'web' (target: 'web'
)。如果使用 require('fs')
,则必须使用带有 brfs 的转换加载器:{ test: /\.js$/, loader: 'transform?brfs!}