Reputation: 610
my friends, I am a beginner and I am trying to build my project that was built with Node, but I don't know the build script. I searched for it a lot but I didn't find a solution. Thank you
package.json
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"engines":{
"node":"16.x"
} ,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"cookie-parser": "^1.4.6",
"dotenv": "^16.0.2",
"express": "^4.18.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.5.4",
"nodemon": "^2.0.19"
}
}
Upvotes: 1
Views: 9108
Reputation: 1
I had the exact same problem and the workaround was to create a vercel.json
file in the root directory with the following config:
{
"version": 2,
"builds": [
{
"src": "server.js",
"use": "@now/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "server.js"
}
]
}
This avoids the use of the /api
folder for simple projects and tells vercel to serve this API as a serverless function.
Reference: https://dev.to/tirthpatel/node-js-express-app-on-vercel-develop-run-deploy-524a
Original Vercel guide: https://vercel.com/guides/using-express-with-vercel
Upvotes: 0
Reputation: 45
I would say the error you are getting is the same as described in Missing Build Scripts (Errors - Vercel Docs).
Apparently, you get this error message when you have a package.json
file located in the root directory of your project, but you have no api
directory and no vercel.json
configuration.
They recommend to set your package.json
file to something similar to this:
{
"scripts": {
"build": "[my-framework] build --output public"
}
}
However, for now it is not possible to have a server-run Node.js web app hosted directly with Vercel.
Vercel is a cloud platform for static frontends and serverless functions.
In order to deploy a Node.js API with Vercel you would need to use their serverless functions or use the Node.js helpers.
Upvotes: 1