简体   繁体   English

Mac 上的 Node.js Heroku 部署 - sh: 1: nodemon: not found / npm ERR! `nodemon fileName.js` / npm ERR! 在...启动脚本失败

[英]Node.js Heroku Deployment on Mac - sh: 1: nodemon: not found / npm ERR! `nodemon fileName.js` / npm ERR! Failed at the...start script

Deploying on Heroku with Node.js using Mac使用MacHeroku上部署Node.js

My issue:我的问题:

State changed from starting to crashed &&  
sh: 1: nodemon: not found &&  
Failed at...start script &&
status 1...code=H10

After creating my front-end, with React , back-end server, with node.js / express.js , and database, with PostgreSQL , I attempted to deploy my server on Heroku with Git .在使用React创建前端、后端服务器、 node.js / express.js和数据库、 PostgreSQL ,我尝试使用GitHeroku上部署我的服务器。 Since I already had Git , I moved onto Heroku CLI因为我已经有了Git ,所以我转向了Heroku CLI

First, from the terminal in my server...首先,从我服务器中的terminal ...

brew install heroku/brew/heroku
heroku create
git remote -v
git push heroku master

If this is not your first time using Heroku ...如果这不是您第一次使用Heroku ......

heroku git:remote -a theUrlYouWant
git push heroku master

...otherwise... Heroku dynamically assigns your app a port, so you can't set the port to a fixed number. ...否则... Heroku动态地为您的应用分配一个端口,因此您无法将端口设置为固定数字。 Heroku adds the port to the env: Heroku 将端口添加到 env:

app.listen(process.env.PORT || 3000, () => {  
  console.log(`app is running on port ${process.env.PORT}`);
})  

...if you added port: ...如果你添加了端口:

git add .
git commit -m "adding port"
git push heroku master

...finally, from my terminal in server: ...最后,从我在服务器中的终端:

➜ folderName git:(master) heroku open  
➜ folderName git:(master) heroku logs --tail

2019-05-08T18:07:23.253827+00:00 heroku[web.1]: Starting process with command npm start  
2019-05-08T18:07:25.323748+00:00 heroku[web.1]: State changed from starting to crashed  
2019-05-08T18:05:17.074233+00:00 app[web.1]: > nodemon fileName.js  
2019-05-08T18:05:17.074235+00:00 app[web.1]:   
2019-05-08T18:05:17.098124+00:00 app[web.1]: sh: 1: nodemon: not found  
2019-05-08T18:05:17.102512+00:00 app[web.1]: npm ERR! file sh  
2019-05-08T18:05:17.102801+00:00 app[web.1]: npm ERR! code ELIFECYCLE  
2019-05-08T18:05:17.103068+00:00 app[web.1]: npm ERR! errno ENOENT  
2019-05-08T18:05:17.103239+00:00 app[web.1]: npm ERR! syscall spawn    
2019-05-08T18:05:17.104259+00:00 app[web.1]: npm ERR! app@1.0.0 start: nodemon fileName.js  
2019-05-08T18:05:17.104361+00:00 app[web.1]: npm ERR! spawn ENOENT  
2019-05-08T18:05:17.104553+00:00 app[web.1]: npm ERR!  
2019-05-08T18:05:17.104692+00:00 app[web.1]: npm ERR! Failed at the app@1.0.0 start script.  
2019-05-08T18:05:17.104841+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 

[...]

2019-05-08T18:05:17.171915+00:00 heroku[web.1]: Process exited with status 1  
2019-05-08T18:05:37.338695+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=yourURL.herokuapp.com request_id=hidden fwd="ip" dyno= connect= service= status=503 bytes= protocol=https  

Heroku runs in a production environment by default so it does not install the dev dependencies. Heroku 默认在生产环境中运行,因此它不会安装开发依赖项。

If you don't want to reinstall nodemon as a dependency, which I think you shouldn't, because it's right place is in devDependencies, not in dependencies...如果您不想将 nodemon 作为依赖项重新安装,我认为您不应该这样做,因为它的正确位置是在 devDependencies 中,而不是在依赖项中...

Instead, you can create a second npm script, in your package.json , to avoid this error by running nodemon only in your localhost:相反,您可以在package.json创建第二个 npm 脚本,通过仅在本地主机中运行nodemon来避免此错误:

"scripts": {
    "start": "node fileName.js",
    "start:dev": "nodemon fileName.js"
},  

And when you want to run the project locally, just run in your terminal npm start:dev and it will load fileName.js with nodemon .当你想在本地运行项目时,只需在你的终端npm start:dev ,它就会用nodemon加载fileName.js

While in Heroku, npm start runs by default and loads fileName.js from a normal node command and you get rid of that error.在 Heroku 中, npm start默认运行并从普通节点命令加载 fileName.js 并且您摆脱了该错误。

2019-05-08T18:13:40.319989+00:00 heroku[web.1]: State changed from crashed to starting  
2019-05-08T18:13:41.000000+00:00 app[api]: Build succeeded  
2019-05-08T18:13:42.658048+00:00 heroku[web.1]: Starting process with command npm start  
2019-05-08T18:13:44.644005+00:00 app[web.1]: 
2019-05-08T18:13:44.644025+00:00 app[web.1]: > app@1.0.0 start /app  
2019-05-08T18:13:44.644027+00:00 app[web.1]: > node fileName.js  
2019-05-08T18:13:44.644028+00:00 app[web.1]:   
2019-05-08T18:13:45.158694+00:00 app[web.1]: app is running on port 33333  
2019-05-08T18:13:46.293205+00:00 heroku[web.1]: State changed from starting to up  
2019-05-08T18:13:47.788861+00:00 heroku[router]: at=info method=GET path="/" host=yourURL.herokuapp.com request_id=hidden fwd="ip" dyno=web.1 connect=0ms service=11ms status=200 bytes=245 protocol=https

I made this post in hopes to help you avoid the time it took me to debug this issue.我写这篇文章是为了帮助你避免我花时间调试这个问题。

Here`s what worked for me:这对我有用:

In your Heroku app, go to Settings , then click Reveal Config Vars and then add a new record with KEY NPM_CONFIG_PRODUCTION and Value false .在您的 Heroku 应用程序中,转到Settings ,然后单击Reveal Config Vars ,然后使用KEY NPM_CONFIG_PRODUCTIONValue false添加新记录。

I added nodemon to the dependencies in package.json and it is working now.我将 nodemon 添加到 package.json 中的依赖项,现在它正在工作。

 "dependencies": {
    "bcrypt-nodejs": "0.0.3",
    "clarifai": "^2.9.1",
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "knex": "^0.95.4",
    "pg": "^8.6.0", 
    "nodemon": "^2.0.7"
  }

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

相关问题 Nodemon [filename.js]返回bash:nodemon:找不到命令 - Nodemon [filename.js] returns bash: nodemon: command not found Plesk + Phusion 乘客:core-js npm 安装失败 - “npm ERR: sh: node: command not found” - Plesk + Phusion Passenger: core-js npm install fails - "npm ERR! sh: node: command not found" npm ERR! 生成ionic serve命令时失败(询问检查安装的node.js和npm版本) - npm ERR! Failed when make ionic serve command (ask for checking version of node.js and npm installed) npm ERR:缺少脚本:从 heroku 开始 - npm ERR! missing script: start on heroku 尝试使用npm start启动node.js应用,但在浏览器中得到err_empty_response - Trying to start a node.js app using npm start but get err_empty_response in browser Heroku 网站:npm 错误! 缺少脚本:开始 - Heroku web: npm ERR! missing script: start Node js 应用程序的 Azure 部署失败:npm ERR! 代码 EPERM - Azure deployment fails for Node js application : npm ERR! code EPERM 将 node.js 应用程序部署到 heroku 时出错(找不到模块 dotenv 和 npm ERR!errno 1) - Error while deploying node.js application to heroku (cannot find module dotenv, and npm ERR! errno 1) 节点 > npm 开始 > npm ERR - Node > npm start > npm ERR TESTRPC从npm Node.js安装ERR - TESTRPC install ERR from npm Node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM