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

NodejsFunction packages dependencies incorrectly #8031

Closed
RafalWilinski opened this issue May 16, 2020 · 6 comments · Fixed by #8169
Closed

NodejsFunction packages dependencies incorrectly #8031

RafalWilinski opened this issue May 16, 2020 · 6 comments · Fixed by #8169
Assignees
Labels
@aws-cdk/aws-lambda-nodejs bug This issue is a bug. in-progress This issue is being actively worked on. p2

Comments

@RafalWilinski
Copy link
Contributor

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

@RafalWilinski RafalWilinski added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 16, 2020
@eladb
Copy link
Contributor

eladb commented May 18, 2020

@jogold any idea?

@jogold
Copy link
Contributor

jogold commented 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.

@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label May 19, 2020
@eladb eladb added the p2 label May 20, 2020
jogold added a commit to jogold/aws-cdk that referenced this issue May 23, 2020
Add a `containerEnvironment` prop to pass environment variables to the
container running Parcel.

Closes aws#7912
Closes aws#8031
@SomayaB SomayaB added the in-progress This issue is being actively worked on. label May 26, 2020
@mergify mergify bot closed this as completed in #8169 Jun 1, 2020
mergify bot pushed a commit that referenced this issue Jun 1, 2020
Add a `containerEnvironment` prop to pass environment variables to the
container running Parcel.

Closes #8031


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@seawatts
Copy link

seawatts commented Apr 1, 2021

I am running into this same issue. @RafalWilinski were you able to resolve this?

I'm using the new esbuild now and am still running into this issue.

I've also set the env var in the bundling block

  "bundling": {
      "environment": {
          "NODE_ENV": "production"
        }
  }

@seawatts
Copy link

seawatts commented Apr 1, 2021

Update: I just turned off minification in the bundling process and it seems to work now.

 "bundling": {
     "environment": {
         "NODE_ENV": "production"
       },
     "minify": false
 }

@eladb
Copy link
Contributor

eladb commented Apr 1, 2021

@jogold can you take a look?

@jogold
Copy link
Contributor

jogold commented 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 graphql/graphql-js#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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-nodejs bug This issue is a bug. in-progress This issue is being actively worked on. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants