Localhost can't connect CORS using ethers.js InfuraProvider

I’m trying to use ethers.js with an Infura provider. When developing locally, trying to make a request from a frontend web app, I’m getting the following error.

“Access to fetch at ‘https://ropsten.infura.io/v3/<PROJECT_ID>’ from origin ‘http://localhost:4200’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.”

Any ideas how to resolve this?

This was related to passing in a secret from the browser. I guess Infura forces a https connection if secret is present. Removing the secret resolved the CORS issue for me.

1 Like

Hey @stu - welcome to the Infura community! So glad you figured it out, and thanks for posting so others who may run into this issue can reference it! :slight_smile: