Support setupProxy.mjs
See original GitHub issueIs your proposal related to a problem?
Now as Node.JS 13.2 un-prefixed ES 6 Modules, I’d like to use ES 6 imports in my setupProxy.mjs, but CRA forces me to use setupProxy.js
.
Describe the solution you’d like
Next to setupProxy.js
, allow to use setupProxy.mjs
(or setupProxy.cjs
).
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:8
Top Results From Across the Web
Proxy to backend with default Next.js dev server - Stack Overflow
Before, when I made apps with create-react-app, I would have a setupProxy.js file that would route API requests similar to this
Read more >setupProxy.js does not work inside React App
Hello, I am having a setupProxy.js file under the src/ folder to deal ... and it doesn't seem to support react or any...
Read more >Migrating from 1.x to 2.0.3 - create-react-app - Breword 文档集合
Object proxy configuration is superseded by src/setupProxy.js ... It's worth highlighting: if your proxy field is a string , e.g. http://localhost:5000 , or...
Read more >Monorepo Setup for Create React App and Components (2/4)
If need help on how to initialize a monorepo, have a look into part 1. ... dist/index.js" has to be .js - using...
Read more >What's new in Create React App 2.0 ? - GeeksforGeeks
Babel: Browser support for modern features of JavaScript has ... your React application right inside the source folder called setupProxy.js ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have a workaround. It’s pretty gross, but it got me unstuck today.
My app is using ESM as the default format. My
/package.json
has"type": "module"
.When I made the change, the react-app-rewired build complained about
/src/setupProxy.js
being ESM so I changed it to.cjs
and thought I was done. Only today (weeks later) did I notice that/src/setupProxy.cjs
is ignored.Here’s the fix for defining your own custom setupProxy logic in an ESM world:
/src/setupProxy.js
./src/setupProxy.js/index.js
. The content of this file must be in CommonJS format./src/setupProxy.js/package.json
that contains the text{ "type": "commonjs" }
. This ensures the neighbouring file is loaded as CommonJS, so it will work when it’s “require’d” in.So, to recap - your structure should now be:
It’s not pretty, but it works!
Thanks to @eric-parsons for the idea of a directory with the
.js
extension. That was the key!@kenlyon Thank you very much ! I don’t know if there is a fix for this problem, but your solution save my day !