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

FormData Related Exception When Utilizing Node.js <16.15.0 #13155

Open
3 tasks done
EdmundasD opened this issue Mar 21, 2024 · 9 comments
Open
3 tasks done

FormData Related Exception When Utilizing Node.js <16.15.0 #13155

EdmundasD opened this issue Mar 21, 2024 · 9 comments
Assignees
Labels
Core Related to core Amplify issues documentation Related to documentation feature requests question General question

Comments

@EdmundasD
Copy link

EdmundasD commented Mar 21, 2024

Before opening, please confirm:

JavaScript Framework

Not applicable

Amplify APIs

REST API, GraphQL API

Amplify Version

v6

Amplify Categories

api

Backend

Amplify CLI

Environment information

  Binaries:
    Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
  Browsers:
    Chrome: 123.0.6312.58
    Safari: 17.2.1
  npmPackages:
    @types/cookie: ^0.6.0 => 0.6.0 
    @types/isomorphic-fetch: ^0.0.35 => 0.0.35 
    @types/node: ^16 => 16.18.38 
    @types/yargs: ^17.0.2 => 17.0.2 
    aws-amplify: ^6.0.18 => 6.0.18 
    cookie: ^0.6.0 => 0.6.0 
    dibs-prettier-config: ^2.0.0 => 2.0.0 
    form-data: ^4.0.0 => 4.0.0 
    isomorphic-fetch: ^3.0.0 => 3.0.0 
    prettier: ^3.2.5 => 3.2.5 
    typedoc: ^0.24.8 => 0.24.8 
    typedoc-plugin-markdown: ^3.15.3 => 3.15.3 
    typescript: ^5 => 5.1.6 
    yargs: ^17.1.1 => 17.1.1 


Describe the bug

According to Amplify's Set up Amplify prerequisites, the Node.js requirement is v14.x or later. However, in the codebase, there is a reference to the global FormData class, which was added to Node.js inv16.15.0, according to the Node.js docs.

Expected behavior

I believe one of two things should be done...

a) The Amplify's prerequisite docs should be updated to require Node.js v16.15.0 or later

b) Include form-data as a dependency from which to reference FormData

Reproduction steps

Occurred while migrating from v5 to v6.

Full disclosure: Have not attempted to create a new project with v6 from scratch to try and reproduce the issue.

Code Snippet

{
  data: {},
  errors: [
    ReferenceError: FormData is not defined
        at transferHandler (/Users/edmundasdaunoras/Documents/Codebases/dibs-utils/dibs-amplify/node_modules/@aws-amplify/api-rest/dist/cjs/apis/common/handler.js:21:27)
        at /Users/edmundasdaunoras/Documents/Codebases/dibs-utils/dibs-amplify/node_modules/@aws-amplify/api-rest/dist/cjs/apis/common/internalPost.js:27:56
        at job (/Users/edmundasdaunoras/Documents/Codebases/dibs-utils/dibs-amplify/node_modules/@aws-amplify/api-rest/dist/cjs/utils/createCancellableOperation.js:25:19)
        at createCancellableOperation (/Users/edmundasdaunoras/Documents/Codebases/dibs-utils/dibs-amplify/node_modules/@aws-amplify/api-rest/dist/cjs/utils/createCancellableOperation.js:48:16)
        at Object.post (/Users/edmundasdaunoras/Documents/Codebases/dibs-utils/dibs-amplify/node_modules/@aws-amplify/api-rest/dist/cjs/apis/common/internalPost.js:26:68)
        at GraphQLAPIClass._graphql (/Users/edmundasdaunoras/Documents/Codebases/dibs-utils/dibs-amplify/node_modules/@aws-amplify/api-graphql/dist/cjs/internals/InternalGraphQLAPI.js:234:60)
  ]
}

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@EdmundasD EdmundasD added the pending-triage Issue is pending triage label Mar 21, 2024
@nadetastic nadetastic added the Core Related to core Amplify issues label Mar 21, 2024
@cwomack cwomack added the GraphQL Related to GraphQL API issues label Mar 26, 2024
@cwomack
Copy link
Member

cwomack commented Apr 1, 2024

@EdmundasD, was the solution to unblock you and resolve this to upgrade your version of Node.js?

Looks like you're correct that we need to update our Set Up Amplify Prerequisites sections to display the proper version of node (as seen in the v5 to v6 migration guides).

@cwomack cwomack added documentation Related to documentation feature requests pending-response and removed pending-triage Issue is pending triage labels Apr 1, 2024
@EdmundasD
Copy link
Author

Thanks for looking into this @cwomack. I have yet to try seeing if this works with an upgraded Node.js version as that currently might not be a viable solution in my specific case. But, I can certainly try it on my local machine.

@cwomack
Copy link
Member

cwomack commented Apr 2, 2024

@EdmundasD, let me know upgrading to a more recent version of Node.js resolves the issue for you. Can you confirm if setting skipLibCheck to true in your ts.config under compilerOptions is another way to work around the errors? Thanks.

@EdmundasD
Copy link
Author

So I played around with this and this is what I found:

  • Adding "skipLibCheck": true to the tsconfig.json did not help.
  • --experimental-fetch flag is needed if running with Node.js version between 16.15.0 and 17.9.1.
  • This works as expected with Node.js 18.0.0.

@chrisbonifacio chrisbonifacio added the to-be-reproduced Used in order for Amplify to reproduce said issue label Apr 15, 2024
@chrisbonifacio
Copy link
Member

Hi @EdmundasD can you confirm what version of aws-amplify you are using so that we can reproduce the issue? It seems a while back we specifically addressed a similar issue in a PR

@EdmundasD
Copy link
Author

Sure @chrisbonifacio. I'm using v6.0.18.

@chrisbonifacio
Copy link
Member

chrisbonifacio commented May 14, 2024

Hi @EdmundasD, apologies for the delay. I had some issues downgrading to Node 14 due to the version of python installed on my machine. Tried downgrading with nvm but apparently I'd need to downgrade my version of python3 as well...

image

If you get a chance, can you try reproducing the issue on a fresh project and let us know if the issue persists?

EDIT: downgrading to 16.0.0 should also reproduce this issue but my local test projects are on Next which require Node 18.17.0+. Can you please share your package.json file so that we use the same framework and versions as your project?

Or, if you can provide a small sample app that would reproduce the issue please do 🙏

@chrisbonifacio chrisbonifacio added pending-response and removed to-be-reproduced Used in order for Amplify to reproduce said issue labels May 14, 2024
@EdmundasD
Copy link
Author

@chrisbonifacio, tried with latest aws-amplify version of 6.3.1 but still encountering the same error.

Went through Amplify's docs and created a small example: https://github.com/EdmundasD/amplifyv6/tree/main

Let me know if you have any questions.

@chrisbonifacio
Copy link
Member

Thank you for the repo @EdmundasD. I was able to reproduce the issue consistently. We will be updating the docs to reflect the correct node version support.

@chrisbonifacio chrisbonifacio removed the GraphQL Related to GraphQL API issues label Jun 13, 2024
@cwomack cwomack removed the bug Something isn't working label Oct 17, 2024
@cwomack cwomack assigned cwomack and unassigned chrisbonifacio Oct 17, 2024
@cwomack cwomack added the question General question label Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Related to core Amplify issues documentation Related to documentation feature requests question General question
Projects
None yet
Development

No branches or pull requests

4 participants