我正在设置一个 json-server 并安装它并将其分配给我的 npm start 命令,就像这样
"scripts": {
"start": "json-server -p 3001 -w db.json"
但每次我在终端上输入 npm start 我都会收到这个错误
> api-server@1.0.0 start C:\Work\React-projects\streams\api-server
> json-server -p 3001 -w db.json
'json-server' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! api-server@1.0.0 start: `json-server -p 3001 -w db.json`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the api-server@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Abdelaziz\AppData\Roaming\npm-cache_logs\2019-04-06T09_07_30_796Z-debug.log
原文由 Abdelaziz Mohamed 发布,翻译遵循 CC BY-SA 4.0 许可协议
首先,您需要检查
json-server
是否全局安装。或者您可以通过以下方式在全球范围内安装它如果您在项目中本地安装它,请使用
npx
运行它在此处查看 npx 和 npm 之间的区别: https ://stackoverflow.com/a/52018825/11285186