im trying to deploy a project to heroku , everything appears to work just fine but when trying to accsess the url given
this is what i see
can anyone have an idea what seems to be the problem?
i've tried looking for a solution via heroku.com but came up short.
if you need a screenshot of anything please tell me what is relevant cause i'm new at this.
here is the package.json for the backend
{
"name": "server",
"version": "1.0.0",
"engines": { "node": "14.x" },
"description": "production ready server",
"main": "server.js",
"scripts": {
"start": "node server.js",
"server:dev": "set NODE_ENV=development&&nodemon server.js",
"server:prod": "set NODE_ENV=production&&node server.js"
},
"author": "Me",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.17.2",
"express-session": "^1.16.2",
"express-socket.io-session": "^1.3.5",
"mongo": "^0.1.0",
"mongodb": "^3.7.3",
"socket.io": "^4.2.0"
},
"devDependencies": {
"nodemon": "1.18.10"
}
}
Related
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"
After having everything working on my Heroku app for months, I started getting this error yesterday:
no pg_hba.conf entry for host "x.x.x.x", user "xxxxx", database "xxxxz", SSL off"
I've only been working on the client side and haven't changed anything on the server, so I don't know what could be going on.
server package.json
{
"name": "spiral-server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha --require test/setup.js",
"dev": "nodemon src/server.js",
"start": "node src/server.js",
"migrate": "postgrator --config postgrator-config.js",
"migrate:test": "env NODE_ENV=test npm run migrate",
"migrate:production": "env SSL=true DATABASE_URL=$(heroku config:get DATABASE_URL) npm run migrate",
"predeploy": "npm audit",
"deploy": "git push heroku master",
"postdeploy": "npm run migrate:production"
},
"keywords": [],
"engines": {
"node": "12.14.1"
},
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"helmet": "^4.1.0",
"jsonwebtoken": "^8.5.1",
"knex": "^0.21.5",
"morgan": "^1.10.0",
"pg": "^8.3.3",
"postgrator": "^4.0.1",
"postgrator-cli": "^3.2.0",
"xss": "^1.0.8"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^8.1.1",
"nodemon": "^2.0.4",
"supertest": "^4.0.2"
}
}
I'm not sure how to start debugging, when I already had it working perfectly.
The only change I might have made was to the GitHub repo name (I changed a few repo names, and not sure if I changed this one or not)
All my other work has been on the client which is a React app hosted on Vercel.
I get the pg error when I query from localhost, Vercel, or Postman.
Any suggestions?
Try the following.
Add a new PGSSLMODE env variable with require as value under your app settings in Heroku.
Then restart your dyno...
heroku ps:restart
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.
To clarify the issue:
I have built a node server, which works fine. But on pushing to git and cloning elsewhere, it doesn't work in the new location.
Cleared node_modules, and tried npm install.
gitignore has only node_modules directory in it.
package.json contains the following
{
"name": "node-todo-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node server/server.js",
"test": "export NODE_ENV=test || SET NODE_ENV=test && mocha server/**/*.test.js",
"test-watch": "nodemon --exec 'npm test'"
},
"engines": {
"node": "6.2.2"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.15.2",
"express": "^4.14.0",
"jsonwebtoken": "^8.3.0",
"lodash": "^4.15.0",
"mongodb": "^2.2.5",
"mongoose": "^4.5.9",
"validator": "^5.6.0"
},
"devDependencies": {
"expect": "^1.20.2",
"mocha": "^5.2.0",
"nodemon": "^1.10.2",
"supertest": "^3.1.0"
}
}
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.