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

v1.7.0 release bug #6409

Closed
Hyodori04 opened this issue May 20, 2024 · 11 comments · Fixed by #6410
Closed

v1.7.0 release bug #6409

Hyodori04 opened this issue May 20, 2024 · 11 comments · Fixed by #6410

Comments

@Hyodori04
Copy link

Hyodori04 commented May 20, 2024

Describe the bug

After upgrade to 1.7.0 from 1.6.8

ReferenceError: TextEncoder is not defined

error happens

To Reproduce

upgrade to axios 1.7.0

Expected behavior

no error happen

Axios Version

1.7.0

Adapter Version

xhr

Node.js Version

20.13.1

@smg-kayle
Copy link

I have the same issue.
Node version: 18.19.1

@ifzm
Copy link

ifzm commented May 20, 2024

+1 (
Return to 1.6.8 normal

@ddwebdevv
Copy link

ddwebdevv commented May 20, 2024

My app is crashing now because of this error. downgrading didn't help

the error in
node_modules/axios/lib/helpers/trackStream.js

line 20
const encoder = new TextEncoder();

@halil07
Copy link

halil07 commented May 20, 2024

Tests are not working right now

@caramelmelmel
Copy link

Hi, I have found out why: https://github.com/axios/axios/blob/v1.x/lib/helpers/trackStream.js#L20 the TextEncoder class is not defined here and we would need to find an instance of it somewhere. I would like to ask if the maintainers can propose a fix to this as it is breaking our pipeline here else, I would gladly propose a kind fix that has been causing this long term issue?

@hey-juicy0
Copy link

how can I solve this?

@halil07
Copy link

halil07 commented May 20, 2024

how can I solve this?

Change package.json file with "axios": "1.6.8"

Without ^

@hey-juicy0
Copy link

how can I solve this?

Change package.json file with "axios": "1.6.8"

Without ^

it's working!! thank you 😊

@Tirzono
Copy link

Tirzono commented May 20, 2024

The error ReferenceError: TextEncoder is not defined typically occurs when running in a Node.js environment that does not natively support TextEncoder. TextEncoder is a Web API that may not be available in the Node.js environment unless explicitly polyfilled.

To fix this error in for example Jest, you can add a polyfill for TextEncoder. There are a couple of ways to do this:

Method 1: Polyfill Using util from Node.js

Node.js 11 and later versions include TextEncoder and TextDecoder in the util module, which you can use as a polyfill.

  1. Install the util package if it's not already installed:

    npm install util
  2. Add the polyfill in your Jest setup file (e.g., setupTests.js):

    // setupTests.js
    const { TextEncoder, TextDecoder } = require('util');
    
    global.TextEncoder = TextEncoder;
    global.TextDecoder = TextDecoder;
  3. Ensure your Jest configuration includes the setup file. In your jest.config.js, add the following:

    module.exports = {
      // other configuration options...
      setupFilesAfterEnv: ['<rootDir>/setupTests.js'],
    };

Method 2: Polyfill Using text-encoding Package

Another approach is to use the text-encoding package to provide a polyfill for TextEncoder.

  1. Install the text-encoding package:

    npm install text-encoding
  2. Add the polyfill in your Jest setup file (e.g., setupTests.js):

    // setupTests.js
    const { TextEncoder, TextDecoder } = require('text-encoding');
    
    global.TextEncoder = TextEncoder;
    global.TextDecoder = TextDecoder;
  3. Ensure your Jest configuration includes the setup file. In your jest.config.js, add the following:

    module.exports = {
      // other configuration options...
      setupFilesAfterEnv: ['<rootDir>/setupTests.js'],
    };

By adding one of these polyfills, you should be able to resolve the ReferenceError: TextEncoder is not defined error in your Jest tests.

@ddwebdevv
Copy link

for me it's not Jest.
I'm using react native( expo). One of my dependencies using axios. And since update I can't run anything because of this error. And we are building in a cloud.
And adding text-encoding or text-encoding-polyfill didn't help.
In previous versions we didn't have this error.

@huyhua-nvg
Copy link

Not a jest problem, nor a node problem. But rather a jsdom test environment problem.
jsdom/jsdom#2524

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants