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"
}
Related
I am a beginner in node-js and I have been learning it using this this video. I have installed the nodemon package and referenced it in package.json. the issue is when I try to start the app in the index.js I get this
.this is my package.json
{
"name": "hotelmgtandrsrvreactandnodejs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"start": "nodemon index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.2",
"nodemon": "^2.0.20"
}
}
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": ""
}
My json package is below
{
"name": "node-rest-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.3",
"mongoose": "^6.2.3"
}
}
I have exhausted all solutions I have found as most of them point to me having start in my json package which I already do so,
Because nodemon module is not installed
either install manually by below command
npm i nodemon
or add nodemon in pakage.json
{
"name": "node-rest-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.3",
"mongoose": "^6.2.3",
}
"devDependencies": {
"nodemon" : "^2.0.15"
}
}
and after that npm install
I am just getting to learn node and webpack. I was following a tutorial, but I keep running into an error. Details of the error and my setup is given below:
error details
log file
My setup
package.json content
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
},
"dependencies": {
"path": "^0.12.7"
}
}
I have installed different packages through npm to run a simple hello world application in React (I am new to it). After their installation, the package.json has this format.
{
"name": "test",
"version": "1.0.0",
"description": "test",
"main": "index.js"
},
"repository": {
"type": "git",
"url": "https://github.com/theo82"
},
"keywords": [
"test"
],
"author": "Theo Tziomakas",
"license": "ISC",
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2",
"webpack": "^2.2.1"
}
}
After running the npm start in cmd(windows 8.1),I get this error.
npm ERR! Unexpected token ',' at 6:4
npm ERR! },
npm ERR! ^
In various answers people solved this problem by using a clean cache as
npm cache clean
However,this does not work for me:(. Any ideas why is this happening?
Thanks,
Theo.
There are syntax errors in your file. Also you should specify what your start script should do. For example, when you run npm start node should execute the index.js file
{
"name": "test",
"version": "1.0.0",
"description": "test",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"keywords": [
"test"
],
"author": "",
"license": "ISC"
}
The syntax of your package.json have some problem, there is a extra } after the line of the key main
{
"name": "test",
"version": "1.0.0",
"description": "test",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/theo82"
},
"keywords": [
"test"
],
"author": "Theo Tziomakas",
"license": "ISC",
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2",
"webpack": "^2.2.1"
}
}