The command "npm run build" is not working

1

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.

    
asked by anonymous 27.12.2017 / 19:58

1 answer

0

This happens because when you run your index.html with the prefix file:// , it will try to load the dependencies related to this path and since you do not have any applications in http:// serving these assets, / p>

Another thing, some browsers have security policy that prevents script execution in file:// . Soon your page will probably give an exception and it will not work either.

Always run the project on an application that serves it as http , because it is the correct way and you probably will not have any problems.

If you want to see your project compiled in the build folder, you can run a link by pointing the root to it.

In mac or linux, you can execute this command inside the build folder:

python -m SimpleHTTPServer

This will raise a link in localhost:80 .

    
30.12.2017 / 01:51