Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !10228

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

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Administrator requested to merge github/fork/jamescostian/improve-setup-proxy-extension-support into main Dec 10, 2020
  • Overview 3
  • Commits 1
  • Pipelines 0
  • Changes 3

Created by: jamescostian

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 (closed)

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.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/jamescostian/improve-setup-proxy-extension-support