Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted #493

Closed
aubelsb2 opened this issue May 29, 2020 · 3 comments

Comments

@aubelsb2
Copy link

Description

Provide a clear and concise description of the issue, including what you expected to happen.

When I try compile
"auth0": "^2.25.1",
With webpack, I get the following error:

WARNING in ./node_modules/formidable/lib/incoming_form.js 1:43-50
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
 @ ./node_modules/formidable/lib/index.js
 @ ./node_modules/superagent/lib/node/index.js
 @ ./node_modules/rest-facade/src/Client.js
 @ ./node_modules/rest-facade/src/index.js
 @ ./node_modules/auth0/src/auth/index.js
 @ ./node_modules/auth0/src/index.js
 @ ./authenticate_authorizer.js

Reproduction

handler.js

const slsw = require('serverless-webpack');
module.exports = {
    target: 'node',
    entry: slsw.lib.entries,
    mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
    node: false,
    optimization: {
        minimize: true,
    },
    devtool: 'nosources-source-map',
};

package.json

{
  "name": "serverlessopttest",
  "version": "1.0.0",
  "description": "",
  "main": "handler.js",
  "dependencies": {
    "source-map-support": "^0.5.19"
  },
  "devDependencies": {
    "@webpack-cli/init": "^0.3.0",
    "serverless": "^1.71.3",
    "serverless-webpack": "^5.3.2",
    "auth0": "^2.25.1",
    "webpack": "^4.43.0",
    "webpack-cli": "^3.3.11"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

serverless.yml

service: serverless-simple-http-endpoint

frameworkVersion: ">=1.1.0 <2.0.0"

provider:
  name: aws
  runtime: nodejs12.x
custom:
#  optimize:
#    debug: true
##    minify: false
  webpack:
    webpackConfig: 'webpack.config.js'   # Name of webpack configuration file
    includeModules: false   # Node modules configuration for packaging
    packager: 'npm'   # Packager that will be used to package your external modules
#    excludeFiles: src/**/*.test.js # Provide a glob for files to ignore
    keepOutputDirectory: true

functions:
  currentTime:
    handler: handler.endpoint
    events:
      - http:
          path: ping
          method: get
plugins:
#  - serverless-plugin-optimize
  - serverless-webpack

webpack.config.js

const slsw = require('serverless-webpack');
module.exports = {
    target: 'node',
    entry: slsw.lib.entries,
    mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
    node: false,
    optimization: {
        minimize: true,
    },
    devtool: 'nosources-source-map',
};

When run:

>sls deploy
Serverless: Bundling with Webpack...
Time: 8541ms
Built at: 29/05/2020 11:04:33 am
         Asset      Size  Chunks                   Chunk Names
    handler.js  1.33 MiB       0  [emitted]        handler
handler.js.map  1.08 MiB       0  [emitted] [dev]  handler
Entrypoint handler = handler.js handler.js.map
  [0] external "util" 42 bytes {0} [built]
  [1] ./node_modules/rest-facade/src/index.js 154 bytes {0} [built]
  [6] ./node_modules/auth0/src/utils.js 1.95 KiB {0} [built]
 [16] external "fs" 42 bytes {0} [built]
 [18] external "path" 42 bytes {0} [built]
 [48] ./node_modules/object.assign/index.js 355 bytes {0} [built]
 [60] (webpack)/buildin/module.js 497 bytes {0} [built]
 [61] ./node_modules/source-map/source-map.js 405 bytes {0} [built]
[141] ./node_modules/auth0/src/auth/index.js 16.3 KiB {0} [built]
[161] ./handler.js 569 bytes {0} [built]
[162] ./node_modules/source-map-support/source-map-support.js 19.3 KiB {0} [built]
[169] ./node_modules/buffer-from/index.js 1.56 KiB {0} [built]
[170] ./lib/asdf.js 286 bytes {0} [built]
[171] ./node_modules/auth0/src/index.js 244 bytes {0} [built]
[172] ./node_modules/auth0/src/management/index.js 88.6 KiB {0} [built]
    + 465 hidden modules

WARNING in ./node_modules/formidable/lib/incoming_form.js 1:43-50
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
 @ ./node_modules/formidable/lib/index.js
 @ ./node_modules/superagent/lib/node/index.js
 @ ./node_modules/rest-facade/src/Client.js
 @ ./node_modules/rest-facade/src/index.js
 @ ./node_modules/auth0/src/management/index.js
 @ ./node_modules/auth0/src/index.js
 @ ./handler.js
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service serverless-simple-http-endpoint.zip file to S3 (890.88 KB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
..............
Serverless: Stack update finished...
Service Information
service: serverless-simple-http-endpoint
stage: dev
region: us-east-1
stack: serverless-simple-http-endpoint-dev
resources: 11
api keys:
  None
endpoints:
  GET - https://1qae7l63j8.execute-api.us-east-1.amazonaws.com/dev/ping
functions:
  currentTime: serverless-simple-http-endpoint-dev-currentTime
layers:
  None
Serverless: Removing old service artifacts from S3...
Serverless: Run the "serverless" command to setup monitoring, troubleshooting and testing.

Environment

Please provide the following:

  • Version of this library used:
    "auth0": "^2.25.1",

  • Version of the platform or framework used, if applicable:

>node --version
v13.11.0
  • Serverless: ^1.71.3 (latest)
  • Webpack: "^5.3.2" (latest)
  • Other relevant versions (language, server software, OS, browser):
    Win 10
  • Other modules/plugins/libraries that might be involved:
@aubelsb2
Copy link
Author

It also cause the lambda to hang until timeout before it exports the function.

@aubelsb2
Copy link
Author

I was able to find this issue which might be related from the auth0-spa-js package: auth0/auth0-spa-js#447

@jimmyjames jimmyjames added the needs investigation An issue that has more questions to answer or otherwise needs work to fully understand the issue label Aug 4, 2020
@jimmyjames
Copy link
Contributor

Hi @aubelsb2, sorry for the delayed response.

Looking at the stack trace, this appears to be rooted in the formidable library:

 @ ./node_modules/formidable/lib/index.js
 @ ./node_modules/superagent/lib/node/index.js
 @ ./node_modules/rest-facade/src/Client.js
 @ ./node_modules/rest-facade/src/index.js
 @ ./node_modules/auth0/src/management/index.js
 @ ./node_modules/auth0/src/index.js
 @ ./handler.js
S

I found an issue in that library that appears to be a report of the same problem. There's also a workaround suggested, you might want to try that. If that doesn't work or isn't acceptable, I'd suggest either continuing the conversation on that issue, or opening a new issue there.

@jimmyjames jimmyjames removed the needs investigation An issue that has more questions to answer or otherwise needs work to fully understand the issue label Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants