Javascript 使用mongodb Node.js包的网页包错误-关键依赖项:依赖项的请求是一个表达式

Javascript 使用mongodb Node.js包的网页包错误-关键依赖项:依赖项的请求是一个表达式,javascript,mongodb,webpack,serverless,Javascript,Mongodb,Webpack,Serverless,我已经建立了一个项目,仅将其包含在我的代码中: import { MongoClient } from 'mongodb'; 正在导致以下输出: Serverless: Bundling with Webpack... Time: 1491ms Asset Size Chunks Chunk Names src/republish.js 1.97 MB 0 [emitted] [big] src/repu

我已经建立了一个项目,仅将其包含在我的代码中:

import { MongoClient } from 'mongodb';
正在导致以下输出:

Serverless: Bundling with Webpack...
Time: 1491ms
           Asset     Size  Chunks                    Chunk Names
src/republish.js  1.97 MB       0  [emitted]  [big]  src/republish
   [1] ./node_modules/mongodb-core/index.js 1.76 kB {0} [built]
  [15] ./node_modules/mongodb/lib/cursor.js 36.2 kB {0} [built]
  [24] ./node_modules/mongodb/lib/collection.js 97.5 kB {0} [built]
  [29] ./node_modules/mongodb/lib/db.js 42.8 kB {0} [built]
  [94] ./node_modules/mongodb/lib/admin.js 10.5 kB {0} [built]
  [95] ./node_modules/mongodb/lib/topologies/mongos.js 14.9 kB {0} [built]
  [96] ./node_modules/mongodb/lib/topologies/replset.js 16.1 kB {0} [built]
  [97] ./node_modules/mongodb/lib/gridfs/chunk.js 7.21 kB {0} [built]
 [120] ./src/republish.js 295 bytes {0} [built]
 [121] ./node_modules/mongodb/index.js 2.28 kB {0} [built]
 [150] ./node_modules/mongodb/lib/apm.js 1 kB {0} [built]
 [157] ./node_modules/mongodb/lib/gridfs/grid_store.js 65.9 kB {0} [built]
 [158] ./node_modules/mongodb/lib/gridfs-stream/index.js 11.1 kB {0} [built]
 [161] ./src/get-param.js 365 bytes {0} [built]
 [162] ./node_modules/aws-sdk/clients/ssm.js 541 bytes {0} [built]
    + 225 hidden modules

WARNING in ./node_modules/require_optional/index.js
82:18-42 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/require_optional/index.js
 @ ./node_modules/mongodb-core/index.js
 @ ./node_modules/mongodb/index.js
 @ ./src/republish.js

WARNING in ./node_modules/require_optional/index.js
90:20-44 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/require_optional/index.js
 @ ./node_modules/mongodb-core/index.js
 @ ./node_modules/mongodb/index.js
 @ ./src/republish.js

WARNING in ./node_modules/require_optional/index.js
97:35-67 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/require_optional/index.js
 @ ./node_modules/mongodb-core/index.js
 @ ./node_modules/mongodb/index.js
 @ ./src/republish.js
Serverless: INVOKING INVOKE
Path must be a string. Received undefined
我的
webpack.config.js
如下:

const path = require('path');
// eslint-disable-next-line import/no-unresolved
const slsw = require('serverless-webpack');

module.exports = {
  entry: slsw.lib.entries,
  target: 'node',
  module: {
    loaders: [{
      test: /\.js$/,
      loaders: ['babel-loader'],
      include: __dirname,
      exclude: /node_modules/,
    }],
  },
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js',
  },
};

你找到解决办法了吗?