我想将我的应用部署到heroku,但总是有错误。这次我不知道问题是什么。我希望你们中的一些人可以帮助我。它找不到一些文件,如我的模型/用户文件,但我就是不知道为什么。
这是我的Heroku日志--尾部日志:
2020-08-13T10:52:56.332352+00:00 app[web.1]: internal/modules/cjs/loader.js:1033
2020-08-13T10:52:56.332393+00:00 app[web.1]: throw err;
2020-08-13T10:52:56.332394+00:00 app[web.1]: ^
2020-08-13T10:52:56.332394+00:00 app[web.1]:
2020-08-13T10:52:56.332395+00:00 app[web.1]: Error: Cannot find module '../models/User'
2020-08-13T10:52:56.332395+00:00 app[web.1]: Require stack:
2020-08-13T10:52:56.332395+00:00 app[web.1]: - /app/server/controllers/authController.js
2020-08-13T10:52:56.332396+00:00 app[web.1]: - /app/server/routes/auth.js
2020-08-13T10:52:56.332396+00:00 app[web.1]: - /app/server/routes/index.js
2020-08-13T10:52:56.332397+00:00 app[web.1]: - /app/server/index.js
2020-08-13T10:52:56.332404+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1030:15)
2020-08-13T10:52:56.332405+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:899:27)
2020-08-13T10:52:56.332406+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1090:19)
2020-08-13T10:52:56.332406+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:75:18)
2020-08-13T10:52:56.332406+00:00 app[web.1]: at Object.<anonymous> (/app/server/controllers/authController.js:3:14)
2020-08-13T10:52:56.332407+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1201:30)
2020-08-13T10:52:56.332407+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
2020-08-13T10:52:56.332407+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:1050:32)
2020-08-13T10:52:56.332408+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:938:14)
2020-08-13T10:52:56.332408+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1090:19)
2020-08-13T10:52:56.332408+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:75:18)
2020-08-13T10:52:56.332409+00:00 app[web.1]: at Object.<anonymous> (/app/server/routes/auth.js:9:5)
2020-08-13T10:52:56.332409+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1201:30)
2020-08-13T10:52:56.332409+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
2020-08-13T10:52:56.332410+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:1050:32)
2020-08-13T10:52:56.332410+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:938:14) {
2020-08-13T10:52:56.332410+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-08-13T10:52:56.332410+00:00 app[web.1]: requireStack: [
2020-08-13T10:52:56.332411+00:00 app[web.1]: '/app/server/controllers/authController.js',
2020-08-13T10:52:56.332411+00:00 app[web.1]: '/app/server/routes/auth.js',
2020-08-13T10:52:56.332412+00:00 app[web.1]: '/app/server/routes/index.js',
2020-08-13T10:52:56.332412+00:00 app[web.1]: '/app/server/index.js'
2020-08-13T10:52:56.332412+00:00 app[web.1]: ]
2020-08-13T10:52:56.332412+00:00 app[web.1]: }
2020-08-13T10:52:56.341133+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-08-13T10:52:56.341538+00:00 app[web.1]: npm ERR! errno 1
2020-08-13T10:52:56.342556+00:00 app[web.1]: npm ERR! [email protected] start: `cd server && node index.js`
2020-08-13T10:52:56.342757+00:00 app[web.1]: npm ERR! Exit status 1
2020-08-13T10:52:56.342939+00:00 app[web.1]: npm ERR!
2020-08-13T10:52:56.343025+00:00 app[web.1]: npm ERR! Failed at the [email protected] start script.
2020-08-13T10:52:56.343097+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-08-13T10:52:56.350212+00:00 app[web.1]:
2020-08-13T10:52:56.350394+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-08-13T10:52:56.350469+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-08-13T10_52_56_343Z-debug.log
2020-08-13T10:52:56.400429+00:00 heroku[web.1]: Process exited with status 1
2020-08-13T10:52:56.441366+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-13T10:52:56.443848+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-13T10:53:16.623284+00:00 heroku[web.1]: Starting process with command `npm start`
2020-08-13T10:53:21.942790+00:00 app[web.1]:
2020-08-13T10:53:21.942812+00:00 app[web.1]: > [email protected] start /app
2020-08-13T10:53:21.942812+00:00 app[web.1]: > cd server && node index.js
2020-08-13T10:53:21.942813+00:00 app[web.1]:
2020-08-13T10:53:22.935440+00:00 app[web.1]: internal/modules/cjs/loader.js:1033
2020-08-13T10:53:22.935486+00:00 app[web.1]: throw err;
2020-08-13T10:53:22.935487+00:00 app[web.1]: ^
2020-08-13T10:53:22.935487+00:00 app[web.1]:
2020-08-13T10:53:22.935488+00:00 app[web.1]: Error: Cannot find module '../models/User'
2020-08-13T10:53:22.935488+00:00 app[web.1]: Require stack:
2020-08-13T10:53:22.935489+00:00 app[web.1]: - /app/server/controllers/authController.js
2020-08-13T10:53:22.935489+00:00 app[web.1]: - /app/server/routes/auth.js
2020-08-13T10:53:22.935490+00:00 app[web.1]: - /app/server/routes/index.js
2020-08-13T10:53:22.935490+00:00 app[web.1]: - /app/server/index.js
2020-08-13T10:53:22.935491+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1030:15)
2020-08-13T10:53:22.935491+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:899:27)
2020-08-13T10:53:22.935492+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1090:19)
2020-08-13T10:53:22.935492+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:75:18)
2020-08-13T10:53:22.935493+00:00 app[web.1]: at Object.<anonymous> (/app/server/controllers/authController.js:3:14)
2020-08-13T10:53:22.935493+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1201:30)
2020-08-13T10:53:22.935493+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
2020-08-13T10:53:22.935494+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:1050:32)
2020-08-13T10:53:22.935494+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:938:14)
2020-08-13T10:53:22.935495+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1090:19)
2020-08-13T10:53:22.935495+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:75:18)
2020-08-13T10:53:22.935495+00:00 app[web.1]: at Object.<anonymous> (/app/server/routes/auth.js:9:5)
2020-08-13T10:53:22.935496+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1201:30)
2020-08-13T10:53:22.935496+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
2020-08-13T10:53:22.935496+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:1050:32)
2020-08-13T10:53:22.935497+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:938:14) {
2020-08-13T10:53:22.935497+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-08-13T10:53:22.935497+00:00 app[web.1]: requireStack: [
2020-08-13T10:53:22.935498+00:00 app[web.1]: '/app/server/controllers/authController.js',
2020-08-13T10:53:22.935498+00:00 app[web.1]: '/app/server/routes/auth.js',
2020-08-13T10:53:22.935498+00:00 app[web.1]: '/app/server/routes/index.js',
2020-08-13T10:53:22.935499+00:00 app[web.1]: '/app/server/index.js'
2020-08-13T10:53:22.935499+00:00 app[web.1]: ]
2020-08-13T10:53:22.935499+00:00 app[web.1]: }
2020-08-13T10:53:22.973818+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-08-13T10:53:22.974439+00:00 app[web.1]: npm ERR! errno 1
2020-08-13T10:53:22.985453+00:00 app[web.1]: npm ERR! [email protected] start: `cd server && node index.js`
2020-08-13T10:53:22.986433+00:00 app[web.1]: npm ERR! Exit status 1
2020-08-13T10:53:22.986725+00:00 app[web.1]: npm ERR!
2020-08-13T10:53:22.986943+00:00 app[web.1]: npm ERR! Failed at the [email protected] start script.
2020-08-13T10:53:22.987322+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-08-13T10:53:23.007937+00:00 app[web.1]:
2020-08-13T10:53:23.008291+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-08-13T10:53:23.008657+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-08-13T10_53_22_989Z-debug.log
2020-08-13T10:53:23.086999+00:00 heroku[web.1]: Process exited with status 1
2020-08-13T10:53:23.135813+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-13T10:54:07.983291+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gamingartsreact.herokuapp.com request_id=298a36bc-eeab-4a66-94e5-2d320c381119 fwd="93.183.161.162" dyno= connect= service= status=503 bytes= protocol=https
2020-08-13T10:54:08.191444+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=gamingartsreact.herokuapp.com request_id=2840511c-6251-4276-9ad3-73aa6a8efe6a fwd="93.183.161.162" dyno= connect= service= status=503 bytes= protocol=https
字符串
我的后端package.json
{
"name": "softuni-react-gamingarts",
"version": "1.0.0",
"description": "",
"main": "index.js",
"engines": {
"node": "14.5.0",
"npm": "6.14.5"
},
"scripts": {
"client": "cd client && npm run start",
"server": "cd server && nodemon index.js",
"backend": "cd server && nodemon index.js",
"frontend": "cd client && npm run start",
"app": "concurrently --names \"backend,frontend\" \"npm run backend --silent\" \"npm run frontend --silent\"",
"start": "cd server && node index.js",
"heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build"
},
"keywords": [],
"author": "Dimitar Belchev",
"license": "ISC",
"dependencies": {
"axios": "^0.19.2",
"bcrypt": "^5.0.0",
"body-parser": "^1.19.0",
"cloudinary": "^1.22.0",
"compression": "^1.7.4",
"concurrently": "^5.3.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-rate-limit": "^5.1.3",
"handlebars": "^4.7.6",
"helmet": "^4.0.0",
"heroku": "^7.42.6",
"jwt-simple": "^0.5.6",
"linkifyjs": "^2.1.9",
"mongoose": "^5.9.28",
"morgan": "^1.10.0",
"multer": "^1.4.2",
"nodemailer": "^6.4.11",
"socket.io": "^2.3.0",
"validator": "^13.1.1"
}
}
型
我的文件结构,如果它有帮助:服务器文件夹,客户端文件夹(与package.json内),package.json文件的服务器。
2条答案
按热度按时间l5tcr1uw1#
查看文件夹结构以及User模型的代码可能会有所帮助,以帮助找出问题。至于更明显的潜在问题,如果没有看到这些细节,我会检查以确保您导出了User模型并仔细检查路由的路径。对我来说,看起来“../models/User”文件不是相对路径期望的位置,或者文件可能由于导出而不可见。
kyks70gy2#
我只是在尝试将NextJS部署到Heroku时遇到了同样的Cannot find module '../models/something'错误。我有一个名为models的文件夹,里面有一些JS文件。在本地运行时,一切都运行得很好,但Heroku似乎不喜欢它。
我所做的就是将模型文件夹重命名为其他文件夹,它工作了。似乎有一些关键字,Heroku不喜欢。