代码之家  ›  专栏  ›  技术社区  ›  ffxsam

使用mongodb时出现Web包错误节点.js包关键依赖项:依赖项的请求是一个表达式

  •  2
  • ffxsam  · 技术社区  · 6 年前

    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/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',
      },
    };
    
    0 回复  |  直到 6 年前