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"
}
}
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.
Related
I have a Node.js Google cloud function which I now try to modularize into two js modules. It works fine locally on my machine but when trying to deploy to Google I get the following error:
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: npm ERR! #babel/cli not accessible from data-model
My main-function is using my data-model module via the following entry in package.json:
"dependencies": {
"#google-cloud/datastore": "^6.1.1",
"data-model": "file:../../data-model",
...
},
The data-model module in turn has the following package.json:
{
"name": "data-model",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "$(gcloud beta emulators datastore env-unset) && export GOOGLE_APPLICATION_CREDENTIALS=\"${GCPPRODFILEPATH}\" && jest --verbose --forceExit",
"build": "npx babel src --out-dir dist"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#google-cloud/datastore": "^6.6.2",
"#google-cloud/storage": "^5.16.1",
"cache-manager-redis-store": "^2.0.0",
"difference": "^1.0.2",
"gstore-node": "^7.2.6",
"ioredis": "^4.28.2",
"lodash": "^4.17.21"
},
"devDependencies": {
"#babel/cli": "^7.16.7",
"#babel/core": "^7.16.7",
"#babel/plugin-transform-modules-commonjs": "^7.16.5",
"#babel/plugin-transform-runtime": "^7.16.5",
"#babel/preset-env": "^7.16.5",
"jest": "^27.4.5"
}
}
and the index.js for data-model is just:
module.exports = Object.assign(
{},
require('./dist/garage'),
require('./dist/car'),
require('./dist/bike'),
require('./dist/util/cacheService'),
);
I'm very much a novice on npm and babel but my understanding was that when I build data-model to /dist babel would transform whatever needed and when I then use the module from main-function babel should be out of the picture.
Clearly my understanding is wrong, but where?
I finally managed to solve this, got a bit side-tracked by the babel/cli error message that CloudFunction threw.
The issue was that my data-model module was in another directory:
"data-model": "file:../../data-model",
I put it inside the main-function instead:
"data-model": "file:data-model",
and it works just fine to deploy to cloud functions.
Why it is so I have no clue but it is kind of documented in the Google Cloud Docs too:
The code for this local module should be stored somewhere other than the node_modules folder within your function's root directory.
This workshop document from openlayers
https://openlayers.org/workshop/en/basics/
contains an example. i am trying to get it running but despite both of
npm start
npm run build
run successfully, however when i access the localhost"please see the attached image"
http://localhost:3000/
OR
http://localhost:1234/
nothing is to be displayed.
please let me know how to solve this issue
package.json
{
"name": "app6",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "parcel index.html",
"build": "parcel build --public-url . index.html"
},
"author": "",
"license": "ISC",
"dependencies": {
"ol": "^6.5.0"
},
"devDependencies": {
"parcel-bundler": "^1.12.5"
}
}
image
Don't stop the process.
npm start
Then let the server running (nicht abbrechen) and go to:
http://localhost:1234/
If you run:
npm run build
you have to copy the build folder to a server to have it run.
I am trying to deploy a mern app, but I get the following error, despite checking my package.json file myself and in multiple websites, what could be the issue here please?
> Compressing source files... done.
Building source:
-----> Node.js app detected
parse error: Expected another key-value pair at line 12, column 3
! Unable to parse package.json
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
If you're stuck, please submit a ticket so we can help:
https://help.heroku.com/
Love,
Heroku
HERE IS MY PACKAGE.JSON FILE
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index",
"dev": "nodemon index",
"build": "cd client && npm run build",
"install-client": "cd client && npm install",
"heroku-postbuild": "npm run install-client && npm run build"
},
"keywords": ["books"],
"author": "",
"license": "ISC",
"dependencies": {
"#hapi/joi": "^17.1.1",
"bcrypt": "^5.0.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.9.18"
},
"devDependencies": {
"nodemon": "^2.0.4"
}
}
try this
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index",
"build": "cd client && npm run build",
"install-client": "cd client && npm install",
"heroku-postbuild": "npm run install-client && npm run build"
},
"keywords": ["books"],
"author": "",
"license": "ISC",
"dependencies": {
"#hapi/joi": "^17.1.1",
"bcrypt": "^5.0.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.9.18"
}
}
I'm setting up a dockerized dev environment for node/typescript for an api project. The goal is to run everything in docker and not have any of installed node, npm or modules installed on the host. This is to isolate all versions of node and all modules from other projects.
./node
docker run \
-it \
-p "8080:80" \
--rm \
-w "/app" \
-v "$(pwd):/app" \
"node:10" "$#"
./npm
#!/bin/sh
./node npm $#
./npx
#!/bin/sh
./node npx $#
./package.json
{
"name": "testapi",
"version": "0.0.1",
"description": "a hello world api",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "npx ts-node src/app.ts",
"lint": "npx ts-lint --project src $#"
},
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^6.2.0",
"fastify": "^1.13.2",
"ts-node": "^7.0.1"
},
"devDependencies": {
"#types/node": "^10.12.15",
"ts-lint": "^4.5.1",
"typescript": "^3.2.2"
}
}
[edit]
I use ./npm install to build my node_modules. The node_modules is in a shared volume so it persists on the host after the container is removed. That way I don't need a Dockerfile to build an image.
[/edit]
When I run the lint command, I get the following error:
testapi$ ./npx ts-lint -i
10: Pulling from node
Digest: sha256:5af431757f84bf7878ff72447eb993fc37afcd975874fff13278157bf83661e6
Status: Image is up to date for docker-remote.registry.kroger.com/node:10
npx: installed 32 in 2.883s
Cannot find module 'typescript'
I think this has to do with module resolution, but I don't know this for sure. I see people install typescript globally, but that would mean I have to do a Dockerfile instead of using the stock node image. I don't mind using a Dockerfile for dev, but I think there should be a way to make this work without doing that.
So I figured out the answer. It wasn't obvious, and I stumbled upon it by accident.
I had installed ts-lint (see package.json above), and I saw an example which referenced tslint (without the hyphen).
So I removed ts-lint and installed tslint and it worked like a champ. I'm not sure what the difference is, but the one with the hyphen does not work in my project configuration. Also, the one without the hyphen installed a higher version number than the one with the hyphen.
See my new package.json containing the working dependency:
{
"name": "testapi",
"version": "0.0.1",
"description": "a hello world api",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "npx ts-node src/app.ts",
"lint": "npx tslint --project ./ 'src/**/*.ts?(x)' $#"
},
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^6.2.0",
"fastify": "^1.13.2",
"ts-node": "^7.0.1"
},
"devDependencies": {
"#types/node": "^10.12.15",
"tslint": "^5.12.0",
"typescript": "^3.2.2"
}
}
This works when run in a docker container, just using the public node:10 image. It doesn't need a Dockerfile to install any global dependencies.
Try
yarn global add tslint typescript
or if it complained for permissions:
sudo yarn global add tslint typescript
I'm trying to install nodemon globally, but I'm getting warning as mentioned in attached picture. May be because of warning, I'm not able to run nodemon.
My package.json
{
"name": "learn",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "himanshu",
"license": "ISC",
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.17.2",
"express": "^4.15.4",
"mongoose": "^4.11.7",
"morgan": "^1.8.2"
}
}
I have added C:\Users\username\AppData\Roaming\npm to the environment variables of my system and it solved my issue.