我有来自节点router.js的原始代码:
import express from "express";
import passport from "passport";
import graphqlHTTP from "express-graphql";
import schema from "./graphql/schema";
import * as authenticator from "./authenticator";
import db from "./models";
const router = express(router);
export const set = app => {
app.use(
"/graphql",
graphqlHTTP({
schema: schema,
graphiql: true,
pretty: true,
formatError: error => ({
message: error.message,
locations: error.locations,
stack: error.stack,
path: error.path
})
})
);
};
它在我的开发环境中运行良好,但是当我使用webpack构建捆绑软件并投入生产时,出现以下错误:
$ node server.js
---> /Volumes/workspace/dev
---> /Volumes/workspace/dev/data/aeirtudb.bin
sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators ../node_modules/sequelize/lib/sequelize.js:242:13
/Volumes/workspace/dev/bundle/webpack:/routes.js:23
const router = express(router);
^
ReferenceError: Ne is not defined
at Module.<anonymous> (/Volumes/workspace/dev/bundle/webpack:/routes.js:23:1)
at r (/Volumes/workspace/dev/bundle/webpack:/webpack/bootstrap:19:1)
at /Volumes/workspace/dev/bundle/webpack:/webpack/bootstrap:83:1
at Object.<anonymous> (/Volumes/workspace/dev/bundle/webpack:/webpack/bootstrap:83:1)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
at startup (internal/bootstrap/node.js:238:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
我不知道这是怎么回事...“ Ne”是哪里来的?
我的webpack构建器配置
var webpack = require("webpack");
var path = require("path");
var 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 = {
entry: "./server.js",
target: "node",
output: {
path: path.join(__dirname, "../bundle"),
filename: "server.js"
},
externals: nodeModules,
plugins: [
new webpack.BannerPlugin({
banner: 'require("source-map-support").install();',
raw: true,
entryOnly: false
})
],
devtool: "sourcemap",
mode: "production"
};