1

I added a custom command to run in my react scripts in my package.json file so that I can run an api server from there

{
  "name": "appfrontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "start-api": "cd .. && cd appbackend && venv/bin/flask run", # This is the command I added
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "proxy": "http://localhost:5000"
}

But npm is not recognising this command. What seems to be the issue? Should I not be able to run my new script with

npm start-api

1 Answer 1

4

You'd need to use npm run start-api

npm only has a few specific commands it recognizes by default. https://docs.npmjs.com/cli-documentation/cli. Anything else you add to your package, you have to use npm run in order to get npm to recognize it.

Sign up to request clarification or add additional context in comments.

Comments

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.