ReferenceError: FormData is not defined

See original GitHub issue

Describe the bug

Recently, In one of my vue3 project we have migrated vue-cli to vite. With vite, we are using jest for testing the component. After the migration, application run without any issue but I have started encountering below issue whenever running jest.

Reference Error: FormData is not defined (latest version - 1.1.3).

Please note that, I have started observing this error from version - 1.0…0. Unfortunately, I wouldn’t be able to share the code to reproduce the issue as its my client code. However, below is the high level structure.

image

We have the axios call in <abc> package which return response. Below is the code snippet causing the error.

import axios from “axios”; const instance = axios.create(); // this line is causing problem. If I comment out this line, issue disappear.

After some digging in axios code, it looks like source of the error is from lib/platform/browser/classes/ index

To Reproduce

No response

Code snippet

No response

Expected behavior

No response

Axios Version

1.0.0

Adapter Version

No response

Browser

chrome

Browser Version

No response

Node.js Version

above 14.19.0

OS

No response

Additional Library Versions

vue - 3.2.39
Jest - 29.2.2
Vite - 3.1.3

Additional context/Screenshots

As I have tried to debug both jest and axios, what I have noticed is that issue occurs at the time of loading the dependency modules it self. Due to that, test case does not even execute.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
ShaktiMandalcommented, Nov 1, 2022

@Romick2005 - actually I was trying to use this package in my code where I was Importing MakeAPICall from this package. Anyway, I found the solution for the original problem - ReferenceError: FormData is not defined.

0reactions
ShaktiMandalcommented, Nov 3, 2022

Closing the issue as it has been resolved. please refer to my previous comment for the solution if you encounter this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FormData is not defined Error in JavaScript | bobbyhadz
The "FormData is not defined Error" error occurs when we try to use the FormData() constructor on the server side, most commonly in...
Read more >
How to use FormData in node.js without Browser?
But above code gives me error as FormData not defined . I am working with ES6. Anybody, who can let me know how...
Read more >
FormData is not defined ' when attempting to call a POST ...
I have the same issue with the model.save() method which is giving ReferenceError: FormData is not defined. In the node modules (node_modules@ ...
Read more >
ReferenceError: formData is not defined - Laracasts
ReferenceError : formData is not defined. I am writing a unit testing code for the Ajax and Laravel project. I am trying to...
Read more >
Exception: ReferenceError: FormData is not defined calling ...
Exception: ReferenceError: FormData is not defined calling exchangeOAuthCodeForAccessToken of TypeScript library ... Can you take a look and see ...
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