简体   繁体   English

package.json 中的自定义反应脚本无法识别

[英]Custom react script in package.json is not recognised

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我在我的 package.json 文件中添加了一个自定义命令以在我的反应脚本中运行,以便我可以从那里运行 api 服务器

{
  "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.但是 npm 无法识别此命令。 What seems to be the issue?似乎是什么问题? Should I not be able to run my new script with我是否应该无法运行我的新脚本

npm start-api

You'd need to use npm run start-api您需要使用npm run start-api

npm only has a few specific commands it recognizes by default. npm 默认只有几个特定的命令可以识别。 https://docs.npmjs.com/cli-documentation/cli . 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.您添加到 package 的任何其他内容,您必须使用npm run才能让 npm 识别它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM