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

Support setupProxy.mjs, cjs, ts, tsx, etc #10228

Closed
wants to merge 1 commit into from
Closed

Support setupProxy.mjs, cjs, ts, tsx, etc #10228

wants to merge 1 commit into from

Conversation

jamescostian
Copy link

@jamescostian jamescostian commented Dec 10, 2020

Uses @babel/register and moduleFileExtensions so that you get just as much love and support in src/setupProxy as you would in, say, src/index.

Fixes #8046 and #6794

Try it out by cloning this branch and then running this:

yarn run create-react-app --template file:packages/cra-template-typescript ../pr-10228
cd ../pr-10228
echo "export default function(a) {throw new Error('It worked!')}" > src/setupProxy.mjs; yarn start
rm src/setupProxy.mjs; echo "module.exports=a=>{throw new Error('It worked!')}" > src/setupProxy.cjs; yarn start
rm src/setupProxy.cjs; echo "export default function(a: any) {throw new Error('It worked!')}" > src/setupProxy.ts; yarn start

Notice how all three times that yarn start are run, you get an error saying "It worked" - this shows that cra paid attention to all the files, parsed their syntax correctly, and ran them (if they weren't run, you wouldn't see that error, and if they weren't parsed properly, you'd get a syntax error).

Additionally, you can drop the --template file:packages/cra-template-typescript bit in line 1, and lines 4 and 5 (cjs and mjs) will work.

Use @babel/register and moduleFileExtensions so that you get just as
much love and support in src/setupProxy as you would in, say, src/index.

Also adds cjs to moduleFileExtensions
@razor-x
Copy link

razor-x commented Jun 14, 2021

Now that ES is stable in Node 14, one cannot use setupProxy and "type": "module" together without this patch. Anything I can do to help unblock this PR?

@stale
Copy link

stale bot commented Jan 9, 2022

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Jan 9, 2022
@TD-DO
Copy link

TD-DO commented Nov 3, 2022

I would very much like this to be merged. I'm trying to do typescript and it's bothering me that I can't do setupProxy.ts

@stale stale bot removed the stale label Nov 3, 2022
@Geraz69
Copy link

Geraz69 commented Oct 24, 2023

I also would like this being merged. Thank you very much for your time if you end up reviewing this :)

@jamescostian jamescostian closed this by deleting the head repository Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support setupProxy.mjs
5 participants