3
我试图将一个node.js express应用程序捆绑到单个文件中进行分发以删除服务器。我正在尝试为此目的使用webpack。捆绑过程正常,但是当我尝试从捆绑包运行应用时,出现错误:如何捆绑“express”node.js应用程序? (with Webpack)
Error: secure random number generation not supported by this browser use chrome, FireFox or Internet Explorer 11"
下面是我的webpack配置。我与node bundle.js
var webpack = require('webpack');
module.exports = {
context: __dirname,
devtool: 'eval',
entry: [
'./index.js'
],
output: {
filename: 'bundle.js',
publicPath: '/public'
},
resolve: {
extensions: ['', '.js', '.json'],
},
module: {
loaders: [
{
test: /\.css$/,
loader: 'null-loader'
},
{
test: /\.json$/,
loader: 'null-loader'
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.NoErrorsPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false }
}),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.OccurenceOrderPlugin(true)
]
}
这里运行的代码是一个完整的错误堆栈:
Error: secure random number generation not supported by this browser
use chrome, FireFox or Internet Explorer 11
at module.exports (webpack:///./~/crypto-browserify/rng.js?:21:13)
at exports.randomBytes (webpack:///./~/crypto-browserify/index.js?:22:23)
at _rng (webpack:///./~/node-uuid/uuid.js?:60:53)
at eval (webpack:///./~/node-uuid/uuid.js?:121:20)
at Object.eval (webpack:///./~/node-uuid/uuid.js?:272:3)
at eval (webpack:///./~/node-uuid/uuid.js?:274:30)
at Object.<anonymous> (/Users/tomi/Github/apps/react-app-test/server/bundle.js:545:2)
at __webpack_require__ (/Users/tomi/Github/apps/react-app-test/server/bundle.js:20:30)
at eval (webpack:///./~/graphql-tools/dist/mock.js?:18:17)
at Object.<anonymous> (/Users/tomi/Github/apps/react-app-test/server/bundle.js:341:2)
我还没有用WebPack完成这项工作,但我已经使用Browserify(很久以前)完成了它。该包似乎包含模仿内置节点模块的Browserify模块(如'crypto-browserify')。而你想要内置的。如何在WebPack中管理它,我不知道,但这就是问题所在。有一个WebPack/Node相关的帖子[这里](http://jlongster.com/Backend-Apps-with-Webpack--Part-I)可能有帮助。 – cartant
我也尝试browserify和结果是不幸的; /我不知道如何强制这些模块加载节点。 – tomitrescak
关我头顶,我不记得了。稍后,我会捅一捅,看看我做了什么。不幸的是,这是前一阵子 - 但我可以记得使用Browserify做的事情,以避免捆绑内置和二进制模块。 – cartant