How should I configure create-react-app to serve app from subdirectory?

In addition to your requirements, I am adding mine: It should be done by CD, through an env variable. If I need to rename the subdirectory, I should only have to change the env variable. It should work with react-router. It should work with scss (sass) and html. Everything should work normally in dev mode … Read more

How to use create-react-app with an older React version?

If you’re here because of react v18, and you want to go down to the previous non-change breaking version, here’s what i did: in your package.json replace: “react”: “^18.0.0” “react-dom”: “^18.0.0” with “react”: “^17.0.2” “react-dom”: “^17.0.2” Then go to your entry file index.js At the top, replace: import ReactDOM from ‘react-dom/client’ with import ReactDOM from … Read more

create-react-app is showing all my code in production, how to hide it?

It seems to be correct behaviour in create-react-app according to Issue #1632. Gaeron: This is expected. You can delete .map files from the build output if you want to disable it, although you’ll get console warnings about them missing. There is no harm in leaving them in though in my opinion. Client code is already … Read more

How to configure react-script so that it doesn’t override tsconfig.json on ‘start’

I was able to do this by using advice from this issue. Put the configuration options react scripts likes to remove in a separate file (e.g. paths.json) and reference it from tsconfig.json via the extends directive. paths.json: { “compilerOptions”: { “baseUrl”: “./src”, “paths”: { “interfaces/*”: [ “common/interfaces/*”], “components/*”: [ “common/components/*”], } } } tsconfig.json { … Read more

Create React App: using environment variables in index.html

I just tried with an (almost) new CRA setup and it works. <head> <title>React App</title> <script type=”text/javascript”> console.log(“%REACT_APP_TEST%”) // OK console.log(“%NODE_ENV%”) // development </script> </head> Did you try restarting the server? I just tried changing the test variable with your example and it works if you restart the development server. As someone pointed out in … Read more

Problem with Visual Studio Code using “react-jsx” as jsx value with create-react-app

This is because VSCode’s Typescript version is not using the newest babel features that create-react-app uses by default. You can change VS Code to use the workspace’s version of Typescript instead, which will fix this issue. Open a TypeScript or JavaScript file and click on the TypeScript version number in the Status Bar. A message … Read more