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