Skip to content

Warning "Critical dependency: the request of a dependency is an expression" when used with Serverless & Webpack #7476

Open
@ericbiewener

Description

@ericbiewener

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
When using the aws-nodejs-typescript template provided by Serverless, bundling mongoose via Webpack results in the following warnings:

WARNING in ./node_modules/mongoose/lib/index.js 8:26-62
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/mongoose/index.js
 @ ./handler.ts
 @ multi ./source-map-install.js ./handler.ts

WARNING in ./node_modules/require_optional/index.js 82:18-42
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/mongodb-core/index.js
 @ ./node_modules/mongoose/lib/connection.js
 @ ./node_modules/mongoose/lib sync ^.*\/connection$
 @ ./node_modules/mongoose/lib/index.js
 @ ./node_modules/mongoose/index.js
 @ ./handler.ts
 @ multi ./source-map-install.js ./handler.ts

WARNING in ./node_modules/require_optional/index.js 90:20-44
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/mongodb-core/index.js
 @ ./node_modules/mongoose/lib/connection.js
 @ ./node_modules/mongoose/lib sync ^.*\/connection$
 @ ./node_modules/mongoose/lib/index.js
 @ ./node_modules/mongoose/index.js
 @ ./handler.ts
 @ multi ./source-map-install.js ./handler.ts

WARNING in ./node_modules/require_optional/index.js 97:35-67
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/mongodb-core/index.js
 @ ./node_modules/mongoose/lib/connection.js
 @ ./node_modules/mongoose/lib sync ^.*\/connection$
 @ ./node_modules/mongoose/lib/index.js
 @ ./node_modules/mongoose/index.js
 @ ./handler.ts
 @ multi ./source-map-install.js ./handler.ts

If the current behavior is a bug, please provide the steps to reproduce.
You can reproduce it with this example repo. After cloning it, run:

$ yarn install
$ sls package

sls package will bundle it with webpack, and you'll see the error.

Alternatively, if you wish to recreate from scratch, you'll need to install serverless and then run:

sls create -p mongoose-serverless -t AAaws-nodejs-typescript
cd mongoose-serverless
yarn add mongoose

Then, in handler.ts, import mongoose and do something with it (like console.log(mongoose)) so that Webpack's treeshaking doesn't ignore it. Then run sls package.

What is the expected behavior?
No warnings

Please mention your node.js, mongoose and MongoDB version.
node: 10.5.0
mongoose: 5.4.8
mongodb: Warnings occur even if this isn't installed, but using 3.1.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    developer-experienceThis issue improves error messages, debugging, or reportingunderlying library issueThis issue is a bug with an underlying library, like the MongoDB driver or mongodb-core

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions