Skip to content

ReferenceError: TextEncoder is not defined in axios >= 1.3.0 #5529

Closed

Description

@Shhad

Describe the issue

Hi,
I've encountered problem after upgrading axios to version 1.3.0.
In my tests, below error has shown up:

ReferenceError: TextEncoder is not defined

at Object. (node_modules/axios/lib/helpers/formDataToStream.js:7:21)

I saw release notes but I didn't find any breaking changes.

Is it a bug?

In version 1.2.6 this error does not exist.

Example Code

No response

Expected behavior

No response

Axios Version

No response

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

No response

OS

No response

Additional Library Versions

No response

Additional context/Screenshots

No response

Activity

  1. DigitalBrainJS commented on Feb 3, 2023

    @DigitalBrainJS
    Collaborator

    You are probably using node.js older than v11.0.0 while we officially support v12 and above. Is this the only problem? Does Axios 1.2.x work on your platform?

  2. JanHamara commented on Feb 3, 2023

    @JanHamara

    Using Node v18.13.0 and having the same issue.

  3. DigitalBrainJS commented on Feb 3, 2023

    @DigitalBrainJS
    Collaborator

    @JanHamara Just tested on 18.12.1

    import axios from 'axios';
    
    const form = new FormData();
    
    form.append('foo', 'bar');
    
    const {data} = await axios.post('http://httpbin.org/post', form);
    
    console.log(process.version, axios.VERSION, data);
    v18.12.1 1.3.0 {
      args: {},
      data: '',
      files: {},
      form: { foo: 'bar' },
      headers: {
        Accept: 'application/json, text/plain, */*',
        'Accept-Encoding': 'gzip, compress, deflate, br',
        'Content-Length': '155',
        'Content-Type': 'multipart/form-data; boundary=axios-1.3.0-boundary-6BBlTU-r5g8APj-bM4F1kQvaW',
        Host: 'httpbin.org',
        'User-Agent': 'axios/1.3.0',
        'X-Amzn-Trace-Id': 'Root=1-63dd3329-227877ef285aa1e81e1d49ce'
      },
      json: null,
      origin: '195.170.179.85',
      url: 'http://httpbin.org/post'
    }
    
  4. rahulthedevil commented on Feb 3, 2023

    @rahulthedevil

    v18.12.1
    1.3.1 {
    args: {},
    data: '',
    files: {},
    form: { foo: 'bar' },
    headers: {
    Accept: 'application/json, text/plain, /',
    'Accept-Encoding': 'gzip, compress, deflate, br',
    'Content-Length': '155',
    'Content-Type': 'multipart/form-data; boundary=axios-1.3.1-boundary-_BWIpm1l0Kgn5YVfdMQy6Rw8f',
    Host: 'httpbin.org',
    'User-Agent': 'axios/1.3.1',
    'X-Amzn-Trace-Id': 'Root=1-63dd3572-36d82a1762ca21e200dda896'
    },
    json: null,
    origin: '49.207.194.31',
    url: 'http://httpbin.org/post'
    }

    Working fine in 1.3.1 also @JanHamara

  5. irfandyj commented on Oct 27, 2023

    @irfandyj

    Hi, I'm using axios 1.5.1 with node version v18.16.0 and still have the issue.

  6. irfandyj commented on Oct 27, 2023

    @irfandyj

    Guys, turns out it fails if you use yarn, I tried reinstalling with npm and it works.

  7. boldwade commented on Jun 13, 2024

    @boldwade

    I have the same problem when using Vite version 5. Vite 4.5.3 works. 🤷‍♂️
    I looked at patching the export, but... meh..

  8. dippas commented on Aug 14, 2024

    @dippas

    this issue was introduce back in v1.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions