ShueiYang
ShueiYang

Reputation: 808

serve package from npm didn't work with React

I want to try the serve package with a React App by doing the following step:

npm install serve --s

then replace the npm start command in package.json like this:

  scripts": {
    "start": "serve -s build",
    "build": "react-scripts build",
    "test": "react-scripts test",
    ...
  },

and then I run npm start i got the error in the console "Uncaught SyntaxError: Unexpected token '<'" etc

however if I uninstall serve --s and put back the package.json like this :

  scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    ...
  },

and then run npm start again it work fine on my local machine, so i think i am doing something wrong in the process and i would like to know why I have issue with the serve package.

Upvotes: 0

Views: 1165

Answers (1)

Ipa Stor
Ipa Stor

Reputation: 164

Looks like you haven't built your /build folder with app bundle. It must be like this:

  1. npm start - to run and edit code
  2. npm run build - to build a bundle(creates/rebuild a /build folder)
  3. serve -s build - serve/start the /build folder

Upvotes: 2

Related Questions