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 warning when bundling XRay SDK with webpack #103

Closed
jhecking opened this issue Feb 28, 2019 · 8 comments
Closed

Critical dependency warning when bundling XRay SDK with webpack #103

jhecking opened this issue Feb 28, 2019 · 8 comments

Comments

@jhecking
Copy link

jhecking commented Feb 28, 2019

Since adding aws-xray-sdk-core to my package dependencies, I'm getting the following warnings when bundling my package using webpack:

WARNING in ./node_modules/aws-xray-sdk-core/lib/patchers/call_capturer.js 41:32-47
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/aws-xray-sdk-core/lib/segments/attributes/aws.js
 @ ./node_modules/aws-xray-sdk-core/lib/aws-xray.js
 @ ./node_modules/aws-xray-sdk-core/lib/index.js
 @ ./node_modules/aws-xray-sdk/lib/index.js
 @ ./src/util/xray.ts
 @ ./src/abc/def/xxx.ts
 @ multi ./source-map-install.js ./src/abc/def/xxx.ts

WARNING in ./node_modules/colors/lib/colors.js 127:29-43
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/colors/safe.js
 @ ./node_modules/winston/lib/winston/config.js
 @ ./node_modules/winston/lib/winston.js
 @ ./node_modules/aws-xray-sdk-core/lib/logger.js
 @ ./node_modules/aws-xray-sdk-core/lib/context_utils.js
 @ ./node_modules/aws-xray-sdk-core/lib/aws-xray.js
 @ ./node_modules/aws-xray-sdk-core/lib/index.js
 @ ./node_modules/aws-xray-sdk/lib/index.js
 @ ./src/util/xray.ts
 @ ./src/abc/def/xxx.ts
 @ multi ./source-map-install.js ./src/abc/def/xxx.ts

Webpack tries to resolve require calls statically to make a minimal bundle. When a library uses variables in a require call (such as this line in aws-xrad-sdk-core), Webpack cannot resolve them statically and imports the entire package.

I'm using v2.2.0 of the SDK.

@chrisradek
Copy link
Contributor

@jhecking
Thank you for reporting this. I'll have to dig into why we used a require to load a JSON file instead of the fs module, since changing that now could break if users were passing in a node module that contained their JSON.

However, when I commented out that line, and also the dynamic require in colors, the size of my bundle didn't decrease at all, so there doesn't appear to be any real gains in changing this (aside from removing the error messages.)

@jhecking
Copy link
Author

jhecking commented Mar 1, 2019

Thanks for looking into this. It's good to know that the bundle size is not affected. However, the warning messages are quite annoying.

The colors package has actually fixed the issue quite a while ago in Marak/colors.js#200. But it looks like you would have to update winston to v3.x in order to get the newer version and I think I saw some ticket about an incompatibility with that version?

@awssandra
Copy link
Contributor

Incompatibility here: #48

Regardless, we should consider upgrading.

@heitorlessa
Copy link

Glad I found this issue here but does your X-Ray tracing work despite the warnings?

I'm trying to run in Lambda with Webpack (typescript->JS) and while I see the same warnings it actually returns an error when I tried to execute:

  "errorMessage": "Cannot read property 'customizeRequests' of undefined",
  "errorType": "TypeError",

Usage:

const AWSXRay = require('aws-xray-sdk-core')

import { DynamoDB } from 'aws-sdk';
const client: DynamoDB.DocumentClient = new DynamoDB.DocumentClient();

// for the lack of types 
AWSXRay.captureAWSClient((DynamoDB.DocumentClient as any).service);

@heitorlessa
Copy link

Glad I found this issue here but does your X-Ray tracing work despite the warnings?

I'm trying to run in Lambda with Webpack (typescript->JS) and while I see the same warnings it actually returns an error when I tried to execute:

  "errorMessage": "Cannot read property 'customizeRequests' of undefined",
  "errorType": "TypeError",

Usage:

const AWSXRay = require('aws-xray-sdk-core')

import { DynamoDB } from 'aws-sdk';
const client: DynamoDB.DocumentClient = new DynamoDB.DocumentClient();

// for the lack of types 
AWSXRay.captureAWSClient((DynamoDB.DocumentClient as any).service);

Nvm, managed to get it working now regardless of this warning, answer here in case anyone finds themselves in the same situation in the future:

const AWSXRay = require('aws-xray-sdk-core')
import { DocumentClient } from 'aws-sdk/clients/dynamodb';

let client: DocumentClient;
client = new DocumentClient();

AWSXRay.captureAWSClient((client as any).service);

@xtheshumanator
Copy link

Hello,

Is there an ETA to fix this? I'm looking at https://github.com/aws/aws-xray-sdk-node/blob/master/packages/core/CHANGELOG.md and I noticed that v2.4.0 was meant to fix this but I'm still seeing the issue on v.2.5.0.

#190 appears to have been 'merged' but it's unclear when it will be released?

Thanks.

@willarmiros
Copy link
Contributor

Hi @theshumanator,
#190 will be released in 3.0.0-alpha.1, which is being tracked in #157. It is projected to be released shortly after the holidays.

@srprash
Copy link
Contributor

srprash commented Jan 9, 2020

The 3.0.0-alpha.1 is now released.

@srprash srprash closed this as completed Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants