繁体   English   中英

无法运行反应js项目

[英]Unable to run react js project

我有一个使用 react js 构建的项目我想在本地执行它

到目前为止我做了什么:

1)安装node.js(windows 64位)

2) 从https://www.tutorialspoint.com/reactjs/reactjs_environment_setup.htm一直到第 3 步

我现在有

1)c://程序文件/nodejs/node_modules

2) 桌面/reactApp/node_modules

我将我的项目文件夹放在 reactApp/. 所以 package.json 在 reactApp/package.json

现在当我尝试运行npm start

 C:\Users\xxx\Desktop\reactApp>npm start > liquid@0.1.0 start C:\Users\jitendra\Desktop\reactApp > PORT=8080 react-scripts start 'PORT' is not recognized as an internal or external command, operable program or batch file. npm ERR. code ELIFECYCLE npm ERR. errno 1 npm ERR: liquid@0.1.0 start. `PORT=8080 react-scripts start` npm ERR. Exit status 1 npm ERR, npm ERR, Failed at the liquid@0.1:0 start script 'PORT=8080 react-scripts start': npm ERR, Make sure you have the latest version of node.js and npm installed: npm ERR. If you do: this is most likely a problem with the liquid package: npm ERR. not with npm itself npm ERR Tell the author that this fails on your system npm ERR PORT=8080 react-scripts start npm ERR You can get information on how to open an issue for this project with npm ERR npm bugs liquid npm ERR Or if that isn't available you can get their info via npm ERR npm owner ls liquid npm ERR There is likely additional logging output above npm ERR A complete log of this run can be found in npm ERR C \Users\jitendra\AppData\Roaming\npm-cache\_logs\2017-05-03T08_13_40_048Z-debug log

这是我的package.json文件

{ "name": "liquid", "version": "0.1.0", "private": true, "devDependencies": {}, "dependencies": { "bootstrap": "^4.0.0-alpha.6", "chart.js": "^2.5.0", "google-map-react": "^0.23.0", "lodash": "^4.17.2", "moment": "^2.18.1", "prop-types": "^15.5.8", "react": "^15.5.4", "react-chartjs-2": "^2.0.5", "react-dom": "^15.5.4", "react-redux": "^5.0.1", "react-router": "^2.8.1", "react-router-redux": "^4.0.5", "react-scripts": "^0.9.5", "react-sortable-tree": "^0.1.17", "react-table": "^5.5.3", "reactstrap": "^4.3.0", "redux": "^3.6.0", "redux-logger": "^2.7.4", "redux-thunk": "^2.1.0", "whatwg-fetch": "^2.0.1" }, "scripts": { "start": "PORT=8080 react-scripts start", "build": "react-scripts build && aws s3 sync build/ s3://xxx.co/1micro", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" }, "homepage": "http://xxx.co/1micro" }

在您的项目根目录创建一个.env文件,然后在PORT=3005中指定端口号,然后在 package json 启动脚本使用,如"start": "react-scripts start"

package json 文件示例如下

{ "name": "r", "version": "0.1.0", "private": true, "devDependencies": { "react-scripts": "0.8.4" }, "dependencies": { "react": "^15.4.2", "react-dom": "^15.4.2" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" } }

该 PORT 命令仅适用于 Unix。 尝试打开命令 window 并以 windows 方式设置端口变量,我认为它是(在 powershell 中):

 $env:PORT=3005

或者,在正常命令 window 中:

 set PORT=3005

然后您可以通过运行检查工作:

 echo %PORT%

这应该返回 3005。然后,导航到您的 reactApp 目录并运行:

 react-scripts start

如果上述解决方案不能解决您的问题,请尝试以下对我有用的方法:

如果您无法启动 react js 项目,请执行以下步骤:

  1. 打开package.json文件
  2. 内部脚本用下面的“start”替换启动命令:“set PORT=3006 && react-scripts start”

暂无
暂无

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

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