Can't deploy Node.js project to Vercel - 404: NOT_FOUND - node.js

I added valid Environment Variables (PORT and Database URI) to Vercel.
When searching I found that whole project must be wrapped in "api" folder so i did it.
This is my configuration. I added everything I found. Am I missing something or i added something wrong?.
vercel.json
{
"version": 2,
"builds": [
{
"src": "./api/index.ts",
"use": "#vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "./api/index.ts"
}
]
}
package.json
{
"name": "back-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon api/index.ts"
},
"engines": {
"node": "16.x"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#types/express": "^4.17.16",
"#types/mongoose": "^5.11.97",
"#types/node": "^18.11.18",
"#types/nodemon": "^1.19.2",
"nodemon": "^2.0.20",
"typescript": "^4.9.5"
},
"dependencies": {
"body-parser": "^1.20.1",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"mongoose": "^6.9.1"
}
}
Vercel 404 Page`
I tried to deploy my app on vercel

Related

Error: Cannot find module Please verify that the package.json has a valid "main" entry

i will delete the node modules file again reinstall npm i but my problem couldn't solve the problem
here's the code ok package.json
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.1.0",
"body-parser": "^1.20.1",
"cctx": "^1.0.1",
"dotenv": "^16.0.3",
"express": "npm:Express#^3.0.1",
"Express": "^3.0.1"
},
"devDependencies": {
"nodemon": "^2.0.20"
}
}

Node - Error Cannot find module 'X' imported from X after pkg

I made a project with nodejs which is using Piscina.
So I got two scripts, my main.js which is used to run all the threads with my worker check.js, but when I try to compile my project with "pkg package.json" and I run the exe, it launches correctly and with the correct interface, but I have this error which appears afterwards:
"Error Cannot find module 'C:\snapshot\new\check.js' imported from C:\snapshot\new\node_modules\piscina\dist\src\worker.js"
I don't understand this error because check.js is not imported from node_modules\piscina\dist\src\worker.js which is the default Piscina worker.js
My package.json file:
{
"name": "tool",
"version": "1.0.0",
"main": "main.js",
"bin": {
"main": "./main.js"
},
"scripts": {
"start": "cross-env NODE_OPTIONS=--max-old-space-size=8192 main.js"
},
"pkg": {
"assets": [
"node_modules/piscina/dist/src/worker.js",
"check.js",
],
"outputPath": ".dist"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"piscina": "^3.2.0",
"node-bash-title": "^0.0.2",
"node-fetch": "^3.2.10",
"systeminformation": "^5.12.7",
"crypto": "^1.0.1",
"http": "^0.0.1-security",
"path": "^0.12.7"
},
"description": ""
}

Parse error: Expected another key-value pair

I'm trying to host a bot for Discord in Heroku, but when doing git push heroku master it gives me this error:
Node.js app detected
remote: parse error: Expected another key-value pair at line 41, column 1
remote: ! Unable to parse package.json
remote:
remote:
remote: -----> Build failed
remote: parse error: Expected another key-value pair at line 41, column 1
remote: parse error: Expected another key-value pair at line 41, column 1
remote: parse error: Expected another key-value pair at line 41, column 1
This is the content of the package.json file
{
"name": "sebas",
"version": "0.0.5",
"description": "un bot cualquiera",
"main": "index.js",
"engines": {
"node": "8.x",
"npm": "*"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/synicalsyntax/discord.js-heroku.git"
},
"keywords": [
"heroku",
"discord.js"
],
"author": "miguerubsk",
"license": "ISC",
"homepage": "https://github.com/synicalsyntax/discord.js-heroku#readme",
"dependencies": {
"bufferutil": "^3.0.3",
"discord.io": "^2.5.3",
"discord.js": "^11.3.2",
"ffmpeg": "0.0.4",
"ffmpeg-binaries": "^3.2.2",
"node-gyp": "^3.6.2",
"opusscript": "0.0.6",
"uws": "^9.14.0",
"winser": "^1.0.3",
"ytdl-core": "^0.20.2"
},
"devDependencies": {},
"bugs": {
"url": "https://github.com/synicalsyntax/discord.js-heroku/issues"
},
}
You simply needed to remove the comma at the end, as Chris said. This should be the code:
{
"name": "sebas",
"version": "0.0.5",
"description": "un bot cualquiera",
"main": "index.js",
"engines": {
"node": "8.x",
"npm": "*"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/synicalsyntax/discord.js-heroku.git"
},
"keywords": [
"heroku",
"discord.js"
],
"author": "miguerubsk",
"license": "ISC",
"homepage": "https://github.com/synicalsyntax/discord.js-heroku#readme",
"dependencies": {
"bufferutil": "^3.0.3",
"discord.io": "^2.5.3",
"discord.js": "^11.3.2",
"ffmpeg": "0.0.4",
"ffmpeg-binaries": "^3.2.2",
"node-gyp": "^3.6.2",
"opusscript": "0.0.6",
"uws": "^9.14.0",
"winser": "^1.0.3",
"ytdl-core": "^0.20.2"
},
"devDependencies": {},
"bugs": {
"url": "https://github.com/synicalsyntax/discord.js-heroku/issues"
}
}

heroku can't start nodejs app

my app works fine local. But when I upload it to github and try to start it with heroku, it says "application error". The build log doesn't show any errors but the app log shows this:
and I think I my port connection is right:
const config = {
port: process.env.PORT || 3000,
};
app.listen(config.port);
package.json:
{
"name": "labo4",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon ."
},
"author": "",
"license": "ISC",
"dependencies": {
"ejs": "^2.5.7",
"express": "^4.16.3",
"glob": "^7.1.2",
"jade": "^1.11.0",
"path": "^0.12.7"
}
}
package.json
{
"name": "labo4",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"ejs": "^2.5.7",
"express": "^4.16.3",
"glob": "^7.1.2",
"jade": "^1.11.0",
"path": "^0.12.7"
}
}
By default Heroku will search for a start in your package.json so edit it as above.

Update Packages.json automatically with the pre-installed moduels in NODEJS

In my local machine, I worked on a node.js app, I had installed many packages before initializing the package.json.
When I initialized the Package.json using:
npm init
I got the package.json but it does not contain all the dependencies that exist in the node_modules,
Which caused me a problem of missing packages when I moved to the production server (I run npm install)
Is there a way to automatically include all of them in the dependencies part.
Here is the JSON file I have:
{
"name": "xxxx",
"version": "1.0.0",
"description": "xxxxxxx",
"main": "server.js",
"dependencies": {
"date-utils": "^1.2.21",
"mssql": "^4.0.4",
"mysql": "^2.11.1",
"seriate": "^0.9.0",
"websocket": "^1.0.23",
"winston": "^2.2.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "git+https://gitlab.com/odot-web/hefner-socket.git"
},
"keywords": [
"nodejs",
"hefner",
"socket"
],
"author": "xxxx",
"license": "ISC",
"bugs": {
"url": "https://gitlab.com/odot-web/hefner-socket/issues"
},
"homepage": "https://gitlab.com/odot-web/hefner-socket#README"
}

Resources