My package.json file
{
"name": "creative-agency-server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"start:dev": "nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Meherameem",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"express-fileupload": "^1.2.0",
"fs-extra": "^9.0.1",
"mongodb": "^3.6.2"
},
"devDependencies": {
"#types/dotenv": "^8.2.0",
"dotenv": "^8.2.0",
"nodemon": "^2.0.5"
}
}
After deploying to Heroku it says
-----> Node.js app detected
parse error: Expected another key-value pair at line 21, column 3
! Unable to parse package.json
-----> Build failed
The problem was -
"dotenv": "^8.2.0"
should be inside the dependencies while deploying on Heroku. Weird that the error on the Heroku console was a bit ambiguous.
Related
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"
}
}
So I am simply trying to deploy my node server to Heroku cloud. It is crashing because of the ES modules not supported issue. The specific error I am getting is
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/app/src/routes' is not supported resolving ES modules imported from /app/src/server.js
I am trying to import my routes directory. I have read the solutions on Stack related to this issue, and none of them are working for me. For example inlcuding "type":"module" in my package.json, is NOT working.
What's going on? It runs perfectly locally using 'npm run dev' script.
Ironman
package.json
{
"name": "back-end",
"type": "module",
"version": "1.0.0",
"description": "",
"engines": {
"node": "14.x"
},
"main": "index.js",
"scripts": {
"dev": "nodemon --exec babel-node -r dotenv/config ./src/server.js",
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node -r dotenv/config ./src/server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#babel/core": "7.13.10",
"#babel/node": "7.13.12",
"#babel/preset-env": "7.13.12",
"#sendgrid/mail": "^7.6.0",
"axios": "^0.24.0",
"bcrypt": "^5.0.1",
"dotenv": "^10.0.0",
"esm": "^3.2.25",
"express": "4.17.1",
"googleapis": "^92.0.0",
"jsonwebtoken": "^8.5.1",
"mongodb": "3.6.5",
"uuid": "^8.3.2"
},
"devDependencies": {
"nodemon": "2.0.7"
}
}
The answer, the solution, was to require the esm package on startup:
"start": "node -r esm -r dotenv/config ./src/server.js"
I'm working on server side coding using Node.js. I've noticed Webpack (I think) is randomly creating dist folder with .dev.js files. I'm not running build, I'm starting server with nodemon npm run start.
Image of what I'm talking about
package.json
{
"name": "card-match-game-server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon index.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"nodemon": "^2.0.6"
},
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"lodash.shuffle": "^4.2.0",
"mongoose": "^5.11.6",
"socket.io": "^3.0.4"
}
}
Can someone clarify why those dist folders are auto generated and the purpose of it? Thanks.
Need help to start nodejs server and next js app at the same time using concurrently npm package at our backend. I have written the script in package.json file on backend side but it's not working.
I don't know exactly know even the concurrently is exist for next js or not. The below script is working fine for React-App but not working for Next JS App
package.json (backend)
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node backend/server",
"server": "nodemon backend/server",
"client": "npm start --prefix frontend",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"author": "",
"license": "ISC",
"dependencies": {
"#sendgrid/mail": "^7.4.0",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-jwt": "^6.0.0",
"express-validator": "^6.6.1",
"formidable": "^1.2.2",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.20",
"mongoose": "^5.10.9",
"morgan": "^1.10.0",
"nodemon": "^2.0.5",
"shortid": "^2.2.15",
"slugify": "^1.4.5",
"string-strip-html": "^6.1.0"
},
"devDependencies": {
"concurrently": "^5.3.0"
}
}
package.json(frontend)
{
"name": "frontend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"proxy": "http://127.0.0.1:8000",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "next",
"build": "next build",
"start": "next start"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#zeit/next-css": "^1.0.1",
"aos": "^3.0.0-beta.6",
"isomorphic-fetch": "^3.0.0",
"js-cookie": "^2.2.1",
"jsonwebtoken": "^8.5.1",
"moment": "^2.29.1",
"next": "^9.5.5",
"nprogress": "^0.2.0",
"prop-types": "^15.7.2",
"query-string": "^6.13.6",
"react": "^16.14.0",
"react-bootstrap": "^1.4.0",
"react-dom": "^16.14.0",
"react-modal": "^3.11.2",
"react-quill": "^1.3.5",
"react-render-html": "^0.6.0",
"reactstrap": "^8.6.0"
}
}
In your package.json file of the backend, you need to replace
"client": "npm start --prefix frontend",
with
"client": "cd ./frontend && npm run dev"
I am assuming that your Nextjs app is in the frontend folder/directory. change the folder accordingly. Then you can run npm run dev command from the backend directory.
Now you will be able to start nodejs server and next js app at the same time using concurrently npm package
I have a project that is using express for the backend API. The project is working on my local machine but when I try to deploy it on a linux VM I get the error "Cannot find module 'Express'".
The steps I took to produce this error were cloning and cding into the repo, and running npm install. express is listed as a dependency in the package.json file. I tried explicitly running npm install express and npm install -g express and both said that they added and/or updated packages and did not return any errors. I also looked in the node_modules folder and there is an express folder there as well.
My package.json:
{
"name": "user-backend",
"version": "1.0.0",
"private": true,
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev-start": "nodemon server.js",
"nvm-start": "nvm use 8.11.3",
"postnvm-start": "nodemon server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.18.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"cors": "^2.8.4",
"dotenv": "^6.0.0",
"express": "^4.16.3",
"faker": "^4.1.0",
"helmet": "^3.12.1",
"jsonwebtoken": "^8.3.0",
"mongoose": "^5.2.2",
"morgan": "^1.9.0",
"request": "^2.88.0",
"slugify": "^1.3.1",
"validator": "^10.4.0"
},
"devDependencies": {
"nodemon": "^1.18.1"
}
}
Any help would be greatly appreciated. Thank you
This ended up being a simple syntax error in my import ("Express" vs "express")