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

The provided value 'stream' is not a valid enum value of type XMLHttpRequestResponseType #1474

Closed
ghost opened this issue Apr 10, 2018 · 14 comments

Comments

@ghost
Copy link

ghost commented Apr 10, 2018

Summary

I literally copied and pasted the "stream" example and I get the following error:

// GET request for remote image
axios({
  method:'get',
  url:'http://bit.ly/2mTM3nY',
  responseType:'stream'
})
  .then(function(response) {
  response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
});

screen shot 2018-04-10 at 1 44 05 pm

Context

  • axios version: v0.17.1
  • Environment: node v8.2.1, Electron 1.8.4
@chadams
Copy link

chadams commented Apr 11, 2018

I'm getting this exact problem.

@chadams
Copy link

chadams commented Apr 11, 2018

@nbcnc I figured it out, your making an electron app like me. seems you can only get the response.data as a stream in the main thread. What I did to fix this was add

ipcRenderer.send("download"); // in render thread

then in the main thread

app.on("ready", async () => {

  mainWindow = new BrowserWindow({
    show: false,
    width: 1024,
    height: 728
  });
 mainWindow.loadURL(`file://${__dirname}/app.html`);

 ipcMain.on("download", (event, arg) => {
   // axios download code here
 });

good luck

@chriscoderdr
Copy link

I'm getting the same error, I'm using it in a rect-native application.

@affanshahid
Copy link

Getting this in the browser, compiled using CRA (webpack)

@bintoll
Copy link

bintoll commented Jul 29, 2018

I am getting this in simple node app

@gcox
Copy link

gcox commented Oct 10, 2018

@bintoll Are you using jest? If so, that's probably the issue...see this comment: #1418 (comment)

@zeevl
Copy link

zeevl commented Oct 11, 2018

For electron users, try this from the render process:

axios.defaults.adapter = require('axios/lib/adapters/http');

This forces axios to use the node adapter. See #552

@GuilhermeAbacherli
Copy link

GuilhermeAbacherli commented Jun 13, 2019

I'm getting this error in web using Vue.

The provided value 'stream' is not a valid enum value of type XMLHttpRequestResponseType.

axios.request({
method: 'POST',
url: 'http://apilink/endpoint',
data: form,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
responseType: 'stream', // HERE
})
.then(response => {
console.log('LOGIN response', response);
})
.catch(error => {
console.log('LOGIN error', error);
});

image

  • Axios version in package.json: "axios": "^0.19.0";
  • Vue version in package.json: "vue": "^2.6.10";

@smilexu
Copy link

smilexu commented Jul 10, 2019

Got same error in React App
Axios version : 0.19.0

@Monasha1992
Copy link

Monasha1992 commented Jul 19, 2019

For React , try using this in https://github.com/axios/axios#request-config

  // `onDownloadProgress` allows handling of progress events for downloads
  onDownloadProgress: function (progressEvent) {
    // Do whatever you want with the native progress event
  },

check for the data in progressEvent.currentTarget.response

@fazulk
Copy link

fazulk commented Nov 25, 2019

This issue is still happening, is there any other way to get streams through axios?

@chinesedfan
Copy link
Collaborator

As far as I know, responseType=stream is not supported in the xhr adapter, including browsers and situations that users config it explicitly/implicitly. Closed in favor of #479.

@wbjqiqi
Copy link

wbjqiqi commented Apr 8, 2020

someone may still tips error with
axios.defaults.adapter = require('axios/lib/adapters/http');

I found that when we require
axios/lib/adapters/http,
it will be replaced with
axios/lib/adapters/xhr
beacuse of webpack.

In axios's package.json, i found this code
"browser": { "./lib/adapters/http.js": "./lib/adapters/xhr.js" },

It seems like in electron 5+, webpack will replace http to xhr in render.

I delete axios's package.json code i mentioned. 'require('axios/lib/adapters/http')' works.

@janswist
Copy link

I also have exact same error. Two years and no response doesn't look promising.

@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests