question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cross origin null forbidden: Axios tries to make an xhr request in a Node environment, instead of an http request.

See original GitHub issue

Axios tries to make an xhr request in a Node environment, instead of an http request.

// It doesn't work

import axios from 'axios';

const { data } = await axios.get( 'http://example.com' );


// It work

import axios from 'axios';
import adapter from 'axios/lib/adapters/http';

const { data } = await axios.get( 'http://example.com', { adapter } );

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

51reactions
bertho-zerocommented, Mar 15, 2018

It’s a issue due to Jest default environment. https://facebook.github.io/jest/docs/en/configuration.html#testenvironment-string

The test environment that will be used for testing. The default environment in Jest is a browser-like environment through jsdom. If you are building a node service, you can use the node option to use a node-like environment instead.


What creates XMLHttpRequest and misleads this function: https://github.com/axios/axios/blob/9a6abd789f91a87d701116c0d86f1cfbc3295d66/lib/defaults.js#L16-L26


To fix this I had to add this in my jest.config.js file:

{
  // ...
  testEnvironment: 'node'
  // ...
}
0reactions
LeoFC97commented, Jul 31, 2019

@bertho-zero where i can find this file?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Cross origin null forbidden during post request
While performing a post request, I am getting the cross origin null forbidden error. I have an Html page with js file called ......
Read more >
axios - npm
Promise based HTTP client for the browser and node.js. Latest version: 1.2.1, last published: 22 days ago. Start using axios in your project ......
Read more >
Cross-origin Errors - React
If an error is thrown from a different origin the browser will mask its details and React will not be able to log...
Read more >
Adding CORS support to an API proxy | Apigee Edge
CORS (Cross-origin resource sharing) is a standard mechanism that allows JavaScript XMLHttpRequest (XHR) calls executed in a web page to ...
Read more >
axios has been blocked by cors policy - You.com
axios has been blocked by cors policy: response to preflight request doesn't pass access control check: no 'access-control-allow-origin' header is present ...
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