我正在使用 webpack 将我的 es6 同构 React 应用程序分别编译为客户端和服务器包。我已经安装了 mongoose 并试图在我的应用程序的服务器部分使用它,但是当我尝试构建时,我在控制台中遇到了一些可怕的错误:
./~/mongoose/lib/drivers/index.js 中的警告关键依赖项:8:11-74 依赖项的请求是一个表达式 @ ./~/mongoose/lib/drivers/index.js 8:11-74
警告在 ./~/mongoose/lib/drivers/SPEC.md module解析失败:/Users/richie/Code/CreativeFlumeProjects/cf-website/node_modules/mongoose/lib/drivers/SPEC.md Line 2: Unexpected token ILLEGAL You可能需要一个合适的加载器来处理这种文件类型。| | # 驱动程序规范 | | 待办事项@ ./~/mongoose/lib/drivers ^./.*$
./~/express/lib/view.js 中的警告关键依赖项:78:29-56 依赖项的请求是一个表达式 @ ./~/express/lib/view.js 78:29-56
./~/es6-promise/dist/es6-promise.js 中的警告未找到module:错误:无法解析 /Users/richie/Code/CreativeFlumeProjects/cf-website/node_modules/es6-promise/dist 中的module“vertx”解析 /Users/richie/Code/CreativeFlumeProjects/cf-website/node_modules/es6-promise/dist 中的module vertx 在 /Users/richie/Code/CreativeFlumeProjects/cf-website/src /Users/richie/Code/CreativeFlumeProjects 中寻找module/cf-website/src/vertx 不存在(module作为目录)在 /Users/richie/Code/CreativeFlumeProjects/cf-website/src 解析文件 /Users/richie/Code/CreativeFlumeProjects/cf-网站/src/vertx 不存在 /Users/richie/Code/CreativeFlumeProjects/cf-website/src/vertx.js 不存在在 /Users/richie/Code/CreativeFlumeProjects/cf-website/node_modules /Users/richie/Code/CreativeFlumeProjects/cf-website/node_modules/vertx 中寻找module不存在(module作为目录)解析“文件”顶点在 /Users/richie/Code/CreativeFlumeProjects/cf-website/node_modules 解析文件 /Users/richie/Code/CreativeFlumeProjects/cf-website/node_modules/vertx 不存在 /Users/richie/Code/CreativeFlumeProjects/cf-website/ node_modules/vertx.js 不存在 [/Users/richie/Code/CreativeFlumeProjects/cf-website/src/vertx] [/Users/richie/Code/CreativeFlumeProjects/cf-website/src/vertx] [/Users/richie /Code/CreativeFlumeProjects/cf-website/src/vertx.js] [/Users/richie/Code/CreativeFlumeProjects/cf-website/node_modules/vertx] [/Users/richie/Code/CreativeFlumeProjects/cf-website/node_modules/vertx] [/Users/richie/Code/CreativeFlumeProjects/cf-网站/node_modules/vertx.js]@./~/es6-promise/dist/es6-promise.js 132:20-30
./~/bson/lib/bson/index.js 中的警告关键依赖项:20:16-29 依赖项的请求是一个表达式 44:18-31 依赖项的请求是一个表达式 71:19-32依赖请求是一个表达式@./~/bson/lib/bson/index.js 20:16-29 44:18-31 71:19-32
./~/require_optional/index.js 中的警告关键依赖项:63:18-42 依赖项请求是一个表达式 71:20-44 依赖项请求是一个表达式 78:35-67 依赖项请求是一个表达式@ ./~/require_optional/index.js 63:18-42 71:20-44 78:35-67
警告 ./~/require_optional/README.md module解析失败:/Users/richie/Code/CreativeFlumeProjects/cf-website/node_modules/require_optional/README.md 第 1 行:意外令牌非法您可能需要适当的加载程序来处理此问题文件类型。| # require_optional | 解决我们在 node.js 中没有 optionalPeerDependencies 概念的问题,这使得可选地包含本机module变得很麻烦 | @ ./~/require_optional ^./.*$
./~/require_optional/LICENSE module解析失败中的警告:/Users/richie/Code/CreativeFlumeProjects/cf-website/node_modules/require_optional/LICENSE 第 1 行:意外标识符您可能需要适当的加载程序来处理此文件类型。| Apache 许可证 | 2.0 版,2004 年 1 月 |
http://www.apache.org/licenses/@./~/require_optional ^./.*$ /Users/richie/Code/CreativeFlumeProjects/cf-website/public/server.bundle.js:235900 返回地图[req ] || (function() { throw new Error("Cannot find module '" + req + "'.") }()); ^错误:找不到module“./node-mongodb-native”。在 /Users/richie/Code/CreativeFlumeProjects/cf-website/public/server.bundle.js:235900:42 在 webpackContextResolve (/Users/richie/Code/CreativeFlumeProjects/cf-website/public/server.bundle.js:235900 :90) 在 webpackContext (/Users/richie/Code/CreativeFlumeProjects/cf-website/public/server.bundle.js:235897:30) 在 Object. (/Users/richie/Code/CreativeFlumeProjects/cf-website/public/server.bundle.js:48684:37) 在webpack_require (/Users/richie/Code/CreativeFlumeProjects/cf-website/public/server.bundle.js: 20:30)在对象。(/Users/richie/Code/CreativeFlumeProjects/cf-website/public/server.bundle.js:52685:17) 在webpack_require(/Users/richie/Code/CreativeFlumeProjects/cf-website/public/server.bundle.js:20:30) 在 Object. (/Users/richie/Code/CreativeFlumeProjects/cf-website/public/server.bundle.js:236259:15) 在webpack_require(/Users/richie/Code/CreativeFlumeProjects/cf-website/public/server.bundle.js:20:30) 在 Object.exports.contain.exports.reachTemplate.internals.Any.applyFunctionToChildren.internals.Err.toString.internals .getPath.internals.serializer.internals.annotate.internals.Response._prepare.internals.Response._processPrepare.internals.Auth.test.internals.Auth.payload.internals.Auth.response.internals.Authenticator.exports.wrap.internals .isIsoDate.internals.compare.internals.Date.min.internals.Date.max.internals.Connection._init.internals.Connection._start.internals.Connection._stop.internals.Connection._dispatch.internals.Methods._add.internals .state.internals.payload.internals.compare.internals.Number.min.internals.Number.max.internals.Number.greater.internals.Number.less.internals.Number.multiple.internals.Number.integer.internals.Number 。消极的。internals.Number.positive.internals.Object.length.internals.Object.min.internals.Object.max.internals.Object.assert.internals.compare.internals.String.min.internals.String.max.internals.String。 creditCard.internals.String.length.internals.String.regex.internals.String.alphanum.internals.String.token.internals.String.email.internals.String.ip.internals.String.uri.internals.String.isoDate。 internals.String.guid.internals.String.hex.internals.String.hostname.internals.String.lowercase.internals.String.uppercase.internals.Request.internals.Response.writeHead.internals.Topo.add.exports.execute。 internals.prerequisites.internals.handler.internals.fromString.internals.pre.module.exports.internals.Plugin.internals.Plugin.register.internals.Protect.run.internals.Request.internals.Request._execute.internals.Request。 _lifecycle.internals.Request._invoke。internals.Server.start.internals.Server.initialize.internals.Server._start.internals.Server.stop._invoke.exports.send.internals.marshal.internals.fail.internals.transmit.internals.state.internals.input。 export.response.internals.Router.normalize.internals.parseParams.internals.Router.table.internals.Policy.get.internals.Policy._callGenerateFunc.internals.Policy.set.exports.generateKey.exports.encrypt.exports.decrypt. export.hmacWithPassword.exports.seal.exports.unseal.internals.Array.items.internals.Array.ordered.internals.Array.min.internals.Array.max.internals.Array.length.internals.Binary.min.internals。 Binary.max.internals.checkIpV6.exports.validate.internals.validate.internals.Definitions.parse.Items.serial.internals.unsign.Items.serial.internals.unsign.internals.decode.internals.Definitions.format.Items。 serial.exports.prepareValue.internals。encode.internals.sign.internals.Parser.internals.Parser.parse.decoder.once.writeFile.internals.Parser.raw.decoder.once.internals.Parser.multipart.onPart.writeFile.exports.Dispenser.internals.Dispenser。 internals.Client.request.internals.Client.read.internals.Client.parseCacheControl.internals.Client._shortcut.map../connection (/Users/richie/Code/CreativeFlumeProjects/cf-website/public/server.bundle.js :235702:19)
我已经尝试了许多通过谷歌找到的解决方案。将“.node”添加到我的resolve.extensions,添加node-loader,以及node对象的一些额外配置,都无济于事。