My problem is the following when executing the command (To prepare the files for production):
npm run build
It does not show any error, apparently everything went well:
c:\bin\node-v8.9.2-win-x64\teste_novo_projeto\my-app>npm run build
> [email protected] build c:\bin\node-v8.9.2-win-x64\teste_novo_projeto\my-app
> react-scripts build
Creating an optimized production build...
Compiled successfully.
File sizes after gzip:
35.81 KB build\static\js\main.ffeb9945.js
420 B build\static\css\main.8b8d5523.css
The project was built assuming it is hosted at the server root.
To override this, specify the homepage in your package.json.
For example, add this to build it for GitHub Pages:
"homepage" : "http://myname.github.io/myapp",
The build folder is ready to be deployed.
You may serve it with a static server:
npm install -g serve
serve -s build
c:\bin\node-v8.9.2-win-x64\teste_novo_projeto\my-app>
Although there is no error, when the page is executed, the screen displays everything blank, as if there was nothing on the page:
ButwhenIrunthecommand:
npmstart
Itworksnormally:
Atthetimeofthebuild,itpresentsthismessage,whichisvaguetome:
Theprojectwasbuiltassumingitishostedattherootserver.To overridethis,specifythehomepageinyourpackage.json.Forexample, addthistobuilditforGitHubPages:
DoIhavetobuildoneforeachspecifichostIuse?BecauseofthismessageItriedtorunthepageonanapacheserver,butcontinuedtheblankpage.
Thisapplicationdoesnotconsumeanywebserviceitsimplyconvertsthebase64entrytoastringortoanimage.
IstheresomethingIhavetosetupasthe"package.json" before the "build"?
Update
If I edit the file "index.html" the path
src="/static/js/main.ffeb9945.js"
for
src="static/js/main.ffeb9945.js"
It works, but I wanted to know the correct way to do this before even giving the build.
Update
package.json
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-scripts": "1.0.17"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"homepage": "http://localhost/react_build/",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Update - "Jan Cassio" response response
The problem is that the path is initialized with "/", so it will only work if the project is in the root of the host, I have already tested using an apache server and also in both cases the problem happens, but I am in the build created and manually edit the index.html and remove this bar, it works normally, this solves the problem, but I wanted to do it the correct way, I'm initializing now with react I know very little, to say nothing, but I believe there is a form of configuration that it builds, I firmly believe that I am doing something wrong at the time of the build, what I need is to create a project and run it on an Apache server.