question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NodejsFunction packages dependencies incorrectly

See original GitHub issue

NodejsFunction from @aws-cdk/aws-lambda-nodejs which is using Parcel to bundle dependencies does that incorrectly, I’m not sure why. I’ve tried putting function dependencies both at the root of the project and inside function directory.

However, it works correctly when I cd into function directory, run NODE_ENV=production parcel build function.ts" and point NodeJSFunction entry to the built function.

Reproduction Steps

https://github.com/RafalWilinski/cdk-nodejs-function-parcel-bug

const graphql = new NodejsFunction(this, 'yourlambda', {
    entry: './src/graphql-server/function.ts', // Typescript source - does not work
});

But

const graphql = new NodejsFunction(this, 'yourlambda', {
    entry: './src/graphql-server/dist/function.js', // after building using parcel manually - works
});

Error Log

After invocation:

{"errorType":"Error","errorMessage":"Cannot use e \"__Schema\" from another module or realm.\n\nEnsure that there is only one instance of \"graphql\" in the node_modules\ndirectory. If different versions of \"graphql\" are the dependencies of other\nrelied on modules, use \"resolutions\" to ensure only one version is installed.\n\nhttps://yarnpkg.com/en/docs/selective-version-resolutions\n\nDuplicate \"graphql\" modules cannot be used at the same time since different\nversions may have different capabilities and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results.","trace":["Error: Cannot use e \"__Schema\" from another module or realm.","","Ensure that there is only one instance of \"graphql\" in the node_modules","directory. If different versions of \"graphql\" are the dependencies of other","relied on modules, use \"resolutions\" to ensure only one version is installed.","","https://yarnpkg.com/en/docs/selective-version-resolutions","","Duplicate \"graphql\" modules cannot be used at the same time since different","versions may have different capabilities and behavior. The data from one","version used in the function from another could produce confusing and","spurious results.","    at e (/var/task/index.js:64:273)","    at L (/var/task/index.js:78:2521)","    at b (/var/task/index.js:78:2330)","    at $ (/var/task/index.js:78:4892)","    at ee (/var/task/index.js:78:4923)","    at new H (/var/task/index.js:78:4713)","    at H (/var/task/index.js:78:4692)","    at Object.parcelRequire.Y3NB.../polyfills/objectValues.mjs (/var/task/index.js:96:11150)","    at f (/var/task/index.js:1:468)","    at p (/var/task/index.js:1:544)"]}

Environment

  • CLI Version : 1.38
  • Framework Version: 1.38
  • OS : Mac OS
  • Language : English

This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jogoldcommented, May 18, 2020

This is apparently a bug when bundling graphql which can only be solved by setting NODE_ENV=production. Setting env vars is currently not supported unfortunately but will be after #7898 and refactoring of aws-lambda-nodejs.

0reactions
jogoldcommented, Apr 5, 2021

@jogold can you take a look?

Seems to be related to an issue in graphql, there’s some discussion about it at https://github.com/graphql/graphql-js/issues/2801.

@seawatts you can also exclude it from bundling with:

bundling: {
  nodeModules: ['graphql'],
},

see also https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/aws-lambda-nodejs#install-modules

Read more comments on GitHub >

github_iconTop Results From Across the Web

class NodejsFunction (construct) · AWS CDK
The path to the dependencies lock file ( yarn.lock or package-lock.json ). This will be used as the source for the volume mounted...
Read more >
Some modules can be used with NodejsFunction(AWS ...
it seems that the "pdfkit" and "chrome-aws-lambda" are packages ... build your lambda with all of the dependencies as a docker image and...
Read more >
Creating Lambda Layers with TypeScript and CDK
The NodeJsFunction uses esbuild to transpile the TypeScript to JavaScript, which can be run in the Lambda. For the Lambda Layer, it bundles...
Read more >
aws-cdk/aws-lambda-nodejs
The NodejsFunction allows you to define your CDK and runtime dependencies in a single package.json and to collocate your runtime code with ...
Read more >
Automating CDK Version Bumping with AWS Serverless ...
While I think most developers are familiar with the problem with versioning and have adjusted ... We have this package.json dependencies:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found