运行 npm start 时出现“index.js not found”,错误!代码 ELIFECYCLE 和 ENOENT
Posted
技术标签:
【中文标题】运行 npm start 时出现“index.js not found”,错误!代码 ELIFECYCLE 和 ENOENT【英文标题】:"index.js not found" when running npm start, ERR! code ELIFECYCLE and ENOENT 【发布时间】:2021-07-31 02:17:01 【问题描述】:我正在尝试通过 Heroku 运行 Discord 机器人(这会起作用还是整个想法有缺陷?)
但是,我每次运行 npm start
时都会收到 npm 错误代码,并且机器人在 Discord 上保持离线状态。
我已经试过npm cache clean --force
,
rmdir /S /Q node_modules
和 npm install
,但这些都不起作用。
这里是控制台日志:
2021-05-09T11:37:13.225562+00:00 heroku[web.1]: Process exited with status 1
2021-05-09T11:37:13.398582+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-09T11:37:20.322275+00:00 app[api]: Starting process with command `npm start` by user <email redacted>
2021-05-09T11:37:23.274907+00:00 heroku[run.4911]: State changed from starting to up
2021-05-09T11:37:23.427148+00:00 heroku[run.4911]: Awaiting client
2021-05-09T11:37:23.726119+00:00 heroku[run.4911]: Starting process with command `npm start`
2021-05-09T11:37:28.678579+00:00 heroku[run.4911]: Process exited with status 1
2021-05-09T11:37:28.742179+00:00 heroku[run.4911]: State changed from up to complete
2021-05-09T11:44:03.004685+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-09T11:44:05.335454+00:00 heroku[web.1]: Starting process with command `npm start`
2021-05-09T11:44:08.088534+00:00 heroku[web.1]: Process exited with status 1
2021-05-09T11:44:08.229000+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-09T11:44:08.232296+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-09T11:44:08.000901+00:00 app[web.1]:
2021-05-09T11:44:08.000925+00:00 app[web.1]: > CalculatorBot@1.0.0 start /app
2021-05-09T11:44:08.000925+00:00 app[web.1]: > index.js
2021-05-09T11:44:08.000925+00:00 app[web.1]:
2021-05-09T11:44:08.005333+00:00 app[web.1]: sh: 1: index.js: not found
2021-05-09T11:44:08.012134+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-05-09T11:44:08.012381+00:00 app[web.1]: npm ERR! syscall spawn
2021-05-09T11:44:08.012474+00:00 app[web.1]: npm ERR! file sh
2021-05-09T11:44:08.012618+00:00 app[web.1]: npm ERR! errno ENOENT
2021-05-09T11:44:08.016105+00:00 app[web.1]: npm ERR! CalculatorBot@1.0.0 start: `index.js`
2021-05-09T11:44:08.016163+00:00 app[web.1]: npm ERR! spawn ENOENT
2021-05-09T11:44:08.016238+00:00 app[web.1]: npm ERR!
2021-05-09T11:44:08.016285+00:00 app[web.1]: npm ERR! Failed at the CalculatorBot@1.0.0 start script.
2021-05-09T11:44:08.016364+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-05-09T11:44:08.024564+00:00 app[web.1]:
2021-05-09T11:44:08.024647+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-05-09T11:44:08.024701+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-05-09T11_44_08_016Z-debug.log
2021-05-09T11:44:11.422108+00:00 heroku[web.1]: Starting process with command `npm start`
2021-05-09T11:44:14.301131+00:00 heroku[web.1]: Process exited with status 1
2021-05-09T11:44:14.438297+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-09T11:44:14.212635+00:00 app[web.1]:
2021-05-09T11:44:14.212651+00:00 app[web.1]: > CalculatorBot@1.0.0 start /app
2021-05-09T11:44:14.212652+00:00 app[web.1]: > index.js
2021-05-09T11:44:14.212652+00:00 app[web.1]:
2021-05-09T11:44:14.217415+00:00 app[web.1]: sh: 1: index.js: not found
2021-05-09T11:44:14.225315+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-05-09T11:44:14.225593+00:00 app[web.1]: npm ERR! syscall spawn
2021-05-09T11:44:14.225710+00:00 app[web.1]: npm ERR! file sh
2021-05-09T11:44:14.225853+00:00 app[web.1]: npm ERR! errno ENOENT
2021-05-09T11:44:14.229827+00:00 app[web.1]: npm ERR! CalculatorBot@1.0.0 start: `index.js`
2021-05-09T11:44:14.229941+00:00 app[web.1]: npm ERR! spawn ENOENT
2021-05-09T11:44:14.230071+00:00 app[web.1]: npm ERR!
2021-05-09T11:44:14.230234+00:00 app[web.1]: npm ERR! Failed at the CalculatorBot@1.0.0 start script.
2021-05-09T11:44:14.230359+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-05-09T11:44:14.237148+00:00 app[web.1]:
2021-05-09T11:44:14.237336+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-05-09T11:44:14.237482+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-05-09T11_44_14_231Z-debug.log
还有我的package.json
:
"name": "CalculatorBot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts":
"test": "echo \"Error: no test specified\" && exit 1",
"start": "index.js"
,
"keywords": [],
"author": "",
"license": "ISC",
"dependencies":
"discord.js": "^12.5.3",
"math": "0.0.3"
任何想法我需要做些什么来解决这个问题,或者是否可以在 Heroku 上运行 Discord 机器人?
【问题讨论】:
index.js文件相对于根目录在哪里? @Elitezen 所有文件都在同一个目录中,我在 Git CMD 中使用cd
导航到它
【参考方案1】:
将您的 package.json
更改为以下内容
......
"start": "node index.js"
.......
【讨论】:
【参考方案2】:在您的 Procfile 中放入与我在此处列出的相同的行代码
web: node index.js
现在再次尝试使用 Heroku 部署您的 WebApp。
【讨论】:
以上是关于运行 npm start 时出现“index.js not found”,错误!代码 ELIFECYCLE 和 ENOENT的主要内容,如果未能解决你的问题,请参考以下文章
在 React 应用程序中运行 npm start 时出现 babel-jest 依赖问题