"homepage": "."
in package.json
according to this doc
"homepage": ".",
in your package.json
then build again.
Add the following code in you index.js
file and remove service worker register
import { unregister } from './registerServiceWorker';
unregister();
1. Run `npm run eject`.
2. Edit file `webpack.config` in the config folder.
3. Find path with `"static/"` or `"static/js/"` or `"static/css/"` in the file and delete such path.
4. Build your project again.
Just as @Verthon said putting the `"homepage": ".",` in your `package.json` file, in the **top level** like this:
```
{
"name": "myApp",
"homepage": ".",
// all other package.json stuff...
}
```
If you're using `react-router` and trying to open `index.html` directly in the browser (or using electron, which essentially does that), in addition to setting `homepage` as others have suggested, replace your `BrowserRouter` with a `HashRouter`.
If the built files are run in a server environment works. https://create-react-app.dev/docs/deployment/
Oooor as I just found out that I had done again and again: You published the public folder instead of the build folder.
If the error message in the browser console is
Then removing any comment inside the `return` method might solve your problem as it did mine. For me the issue was the inline runtime script was not being run as I was getting the error:Minified React error #152;
This was fixed by adding the `INLINE_RUNTIME_CHUNK=false` variable to the build script.Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-5='), or a nonce ('nonce-...') is required to enable inline execution.
"build": "INLINE_RUNTIME_CHUNK=false react-scripts build",
for the React-Deployment, correctly, you will realise that there is a "homepage":"." // User "." if you are deploying on your local machine, but on a server hosted somewhere you can use your domain or ip address the homepage field.
If it's in the root folder you can use `homepage`
"homepage":"."
in package.json
if it's in any other folder like `https://example.com/admin` you can use
"homepage":"https://example.com/admin"
Working solution for `React` with `typescript` is to add `"homepage": "."` in `package.json`
{
"name": "todo-app",
"version": "0.1.0",
"private": true,
"dependencies": {
},
"scripts": {
},
"eslintConfig": {
},
"browserslist": {
},
"homepage": "."
}
now build the Application with `npm run build` and open the production `html` file.
Specify the path properly or better yet move it out of a component to be referenced in the index.js.