9

I did a build for a React app using npm run-script build and I need to run it. Using npm run webpack is returning an error. Excuse my being very new to React but I really need to know how to run this app. I hope you can help!

My package.json:

{
"name": "dashboard",
"version": "0.1.0",
"private": true,
"dependencies": {
    "axios": "^0.16.2",
    "downloadjs": "^1.4.7",
    "fast-memoize": "^2.2.8",
    "flow-bin": "^0.52.0",
    "lodash": "^4.17.4",
    "mapbox-gl": "^0.39.1",
    "material-ui": "^0.18.7",
    "moment": "^2.18.1",
    "node-sass-chokidar": "^0.0.3",
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-mapbox-gl": "^2.5.0",
    "react-redux": "^5.0.5",
    "react-router": "^4.1.2",
    "react-router-dom": "^4.1.2",
    "react-router-redux": "next",
    "react-tap-event-plugin": "^2.0.1",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0"
},
"devDependencies": {
    "react-emotion": "^7.2.2",
    "react-scripts": "1.0.10",
    "styled-components": "^2.1.2"
},
"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "flow": "flow"
}

Here are the folders and files of the built app

7
  • Might help to show your package.json so we can see what libraries and what scripts you already have. Commented Mar 8, 2018 at 10:04
  • @Stretch0 Sure, I edited it. Commented Mar 8, 2018 at 10:07
  • what's the error? Commented Mar 8, 2018 at 10:08
  • 1
    You don't appear to be using webpack. Does npm run build not create a build file for you? Commented Mar 8, 2018 at 10:08
  • @Philippe Error finding package.json npm ERR! path /Users/aa/Documents/build/package.json npm ERR! code ENOENT npm ERR! errno -2 npm ERR! syscall open npm ERR! enoent ENOENT: no such file or directory, open '/Users/aa/Documents/build/package.json' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent npm ERR! A complete log of this run can be found in: npm ERR! /Users/aa/.npm/_logs/2018-03-08T10_16_56_166Z-debug.log Commented Mar 8, 2018 at 10:18

3 Answers 3

7

As I mentioned in comments.

npm run build uses react-scripts to create a build for you

To run in production:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "flow": "flow",
    "start:prod": 'node dist/app.js'
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you! One more thing: I just realised that I can't run the app statically, aka just by double clicking on index.html, right?
Correct. You need to use npm start to run locally or if you are trying to deploy to production have a start script that runs node dist/app.js. Have added example script to answer
I was wondering about deploying it on server too. Thanks a ton! @Stretch0
@LeeMoe what do you mean? You can use node dist/app.js to run on the server.
2

By looking at "react-scripts": "1.0.10", it seems you created the app using create-react-app.

create-react-app is using yarn by default. So you can run yarn then yarn build (same as npm install and then npm run build)

If you need change webpack configuration. The app have eject first. You can do it by yarn eject. And then you can edit the webpack config file.

Does this help?

Comments

0

Are you using create-react-app? If yes then run "npm run build" in your root folder. This command will run your app

1 Comment

The app isn't written by me but I would assume yes it's done using create-react-app because it has those commands in package.json: ` "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" }`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.