Reactjs json服务器未被识别为内部或外部命令
我正在设置一个json服务器,然后安装它,并将其分配给我的NPMStart命令,如下所示Reactjs json服务器未被识别为内部或外部命令,reactjs,npm,json-server,Reactjs,Npm,Json Server,我正在设置一个json服务器,然后安装它,并将其分配给我的NPMStart命令,如下所示 "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-s
"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
首先,您需要检查是否全局安装了json服务器。或者,您可以通过以下方式进行全局安装:
npm install -g json-server
如果在项目中本地安装,请使用npx运行它
npx json-server --watch db.json
检查npx和npm之间的差异:第一步使用以下命令安装json服务器:
npm安装-g json服务器
然后,您可以运行该命令并使用以下命令选择端口:
npxjson服务器——监视-p3333server.json
将3333更改为所需的端口号,并用伪api的名称替换server.json 在我的例子中,我使用的是React js,我的server.json位于我的应用程序的根目录下。 您可以尝试:
更新node.js版本,适用于node.js 10版本以上的版本
npm i -g json-server
json-server --watch db.json
如果这不起作用
npm i -g json-server
npx json-server --watch db.json
这种方法适用于mac常见的错误是没有全局安装json服务器包 对我有效的方法:我使用命令: npm安装-g json服务器 (-g表示全局安装程序包) 对于测试: json服务器——监视数据/db.json——端口8000 (-watch用于检查数据库文件[here path-data data/db.json],而--port用于手动设置端口[here 8000]) 您现在可以检查端口8000上的数据 http://localhost:8000/anything
(您也可以使用npx)您是如何安装json服务器的?@ArnaudChrist我尝试了一切``npm安装-g json服务器--save``我在全局范围内安装了它,但仍然无法工作,我尝试了npx it显示此信息(npx:installed 236 in 8.971s command not found:json server)您好,您可以运行
npm list-g--depth 0
并检查列表中的json服务器
?我得到了这个:C:\Users\Abdelaziz\AppData\Roaming\npm+--create react-app@2.1.8+--一口-cli@2.1.0+--http-server@0.11.1+--json-server@0.14.2 +-- npm@6.9.0 `-- sudo@1.0.3So,下一步是检查路径环境,确保它有C:\Users\Abdelaziz\AppData\Roaming\npm
多次这样做,但仍然有相同的错误