0
我已经成功使用webpack为我的节点服务器构建了express,但我似乎发现错误不是解决方案。希望可以有人帮帮我。谢谢!
当API被称为
TypeError: $JSON.stringify.apply is not a function
at stringify (webpack:///./~/core-js/library/fn/json/stringify.js?:13:26)
at eval (webpack:///./app/schedules/Route.js?:34:48)
at Layer.handle [as handle_request] (/Users/username/Project/project- server/node_modules/express/lib/router/layer.js:95:5)
的航线代码
.post(function (req, res) {
let url_id = (req.params.id) ? req.params.id : null;
let schedule = JSON.stringify(req.body.data);
...
的WebPack配置部分
const path = require('path');
const webpack = require('webpack');
const fs = require('fs');
var nodeModules = {};
fs.readdirSync('node_modules')
.filter(function(x) {
return ['.bin'].indexOf(x) === -1;
})
.forEach(function(mod) {
nodeModules[mod] = 'commonjs ' + mod;
});
module.exports = {
target: 'node',
devtool: 'eval',
context: __dirname + "/",
entry: './server',
output: {
path: path.join(__dirname, 'dist'),
filename: 'app.js',
//publicPath: '/static/',
},
module: {
loaders: [
{
loader: 'babel-loader',
query: {
presets: ["es2015", "react", "stage-2"],
plugins: ["transform-runtime","transform-class-properties"]
}
},
{
loader: 'json-loader',
test: /\.json$/
}
],
plugins: [
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false,
},
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.IgnorePlugin(/\.(css|less)$/),
new webpack.BannerPlugin('require("source-map-support").install();', { raw: true, entryOnly: false })
]
},
node: {
fs: "empty",
net: 'empty',
tls: 'empty',
dns: 'empty'
},
externals: nodeModules
};