OK, I have an express app which is throwing this error at launch when deployed to Heroku. The app compiles and runs fine locally:
Cannot find module 'mongodb'
This app was running until I redeployed it yesterday ... here is my package.json which was unchanged
{
"name": "fitness-tracker",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"express": "~4.9.0",
"body-parser": "~1.8.1",
"cookie-parser": "~1.3.3",
"promise": "~6.0.1",
"morgan": "~1.3.0",
"serve-favicon": "~2.1.3",
"debug": "~2.0.0",
"mongodb-core": "*",
"mongoskin": "~2.0.0",
"express-handlebars": "~1.1.0",
"moment": "~2.0.0",
"moment-timezone": "^0.3.1",
"q": "~1.0.1",
"compass": "~0.1.0",
"apm": "*"
},
"devDependencies": {
"moment-timezone": "^0.3.1"
}
Ideas?
So the issue was package's resolution based on node version. Since NodeJS is rapidly evolving, it's a good practice to include engines specification in your package.json.
When doing automatic deployments on various cloud providers, this helps them to use only specified node & npm version. This was all the packages that get fetches are built for that node version hence less chances of app to misbehave.
Read more: https://docs.npmjs.com/files/package.json#engines
Also always worth a try: disable the Heroku build cache to recreate the node_modules directory.
In the Heroku CLI write:
$ heroku config:set NODE_MODULES_CACHE=false
$ git commit -am 'disable node_modules cache' --allow-empty
$ git push heroku master
As described here.
Related
I am trying to deploy a web app on Heroku. I am getting the following error
Error: Cannot find module '#heroku/buildpack-registry'
I tried adding the version of node I am using but still didn't help.
I also upgraded Heroku using npm i heroku#7.59.0 this too didn't help.
Any thoughts on this?
This is my package.json
{"name":"gssrDB",
"engines": {
"node": "14.18.0"
}
,
"scripts": {
"dev": "nodemon index.js",
"start": "node index.js"
},
"dependencies": {
"#heroku-cli/plugin-buildpacks": "^7.54.0",
"#heroku/buildpack-registry": "^1.0.1",
"async-file": "^2.0.2",
"cli-ux": "^4.9.3",
"dotenv": "^9.0.2",
"ejs": "^3.1.6",
"ejs-mate": "^3.0.0",
"express": "^4.17.1",
"got": "^8.3.2",
"heroku": "^7.59.0",
"mongodb": "^3.6.6",
"mongoose": "^5.12.9",
"nodemon": "^2.0.13",
"phoenix": "^1.6.0"
}
}
I solved it like this in terminal
$ heroku plugins:install buildpack-registry
$ heroku plugins:install buildpacks
may be it works
I faced a similar problem, and I solved it by using proper node version.
For the current heroku version, node16 works, otherwise it cause error in buildpack
Two things helped in fixing this:
update the heroku CLI
npm install -g heroku
Adding the engines in the package.json with the currently installed node and npm versions
"node": "14.18.0",
"npm": "7.6.3"
}
i'm new with node, i have to deploy my first application.
this is my package.json:
{
"name": "tbcw",
"description": "TheBestCollectors",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules",
"truffle-compile": "truffle compile",
"truffle-serve": "truffle serve",
"truffle-test": "truffle test --network test"
},
"dependencies": {
"vue": "^2.4.4",
"vue-draggable-resizable": "^1.5.1",
"vuex": "^2.4.1",
"web3": "^1.2.11"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^6.0.0",
"babel-preset-env": "^1.7.0",
"cross-env": "^3.0.0",
"css-loader": "^0.25.0",
"ejs": "^2.5.7",
"ejs-compiled-loader": "^2.2.0",
"eslint": "^4.8.0",
"ethereumjs-testrpc": "^4.1.3",
"file-loader": "^0.9.0",
"html-webpack-plugin": "^2.30.1",
"json-loader": "^0.5.7",
"node-sass": "^4.9.4",
"null-loader": "^0.1.1",
"sass-loader": "^5.0.1",
"truffle": "^3.4.11",
"truffle-contract": "^1.1.6",
"vue-loader": "^12.1.0",
"vue-template-compiler": "^2.4.4",
"webpack": "^2.6.1",
"webpack-dev-server": "^2.9.1"
}
}
in local with dev mode everything works correctly.
Now I would like to publish my app on heroku.
after uploading the files with herokuCLI, when i run the app, I get an error page.
reading them via the command "heroku logs --tail"
based on different attempts i got different errors, like webpack not found, start script not found, cross-env not found...
how can i proceed?
Please let me know if you need more info.
thank you for all the replies
Looking at your package.json, it seems your are working on a client-side application. Such applications run in the client's browser, rather than in Node. Heroku is for running server-side applications, so it's probably not the right place to deploy your app.
Take a look at something like Vercel or Netlify instead. They provide tools to automatically build and deploy client-side applications to edge networks with only a few clicks.
Heroku, by default, doesn't install devDependencies. It seems your cross-env and webpack are listed as devDependencies. And you don't even have a start script.
I'm looking for deploying my NodeJS API with AWS.
I tried to use Elastic Beanstalk but I always get this issue:
Image of the error I get
There is my package.json
{
"name": "",
"scripts": {
"start": "node server.js"
},
"version": "0.0.0",
"private": true,
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"express": "^4.16.4",
"hammerjs": "^2.0.8",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.4.20",
"mongoose-unique-validator": "^2.0.2",
"multer": "^1.4.1",
"tslib": "^1.9.0"
}
}
And I also have a nodecommand.config into a folder named ".ebextensions"
option_settings:
aws:elasticbeanstalk:container:nodejs:
NodeCommand: "npm start"
Also, is Elastic Beanstalk the best way to deploy my API ?
Thx for the answers !
Based on the comments.
The primary issue was using rar for deployment packaged instead of zip. After fixing that, config files had to be adjusted to work with Amazon Liunx 2.
My Azure app service is running Node.js version 0.10:
> node -v
D:\home\site\wwwroot
v0.10.28
I am trying to upgrade it to version 8.
There's an article here describing how to do that: https://learn.microsoft.com/en-us/azure/nodejs-specify-node-version-azure-apps
First, I added the key in the Application Settings in Azure Portal:
It didn't work, so I also changed packages.json:
{
"name": "azure_cosmos_db_webservice",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node --inspect server.js"
},
"engines":{"node": "8.x"}, <-- This line added by me
"dependencies": {
"async": "^2.1.2",
"body-parser": "~1.15.2",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"documentdb": "^1.10.0",
"dotenv": "^4.0.0",
"express": "~4.14.0",
"morgan": "~1.7.0",
"serve-favicon": "~2.3.0"
}
}
I've restarted the app service several times by stopping and starting it again.
However, node -v in the console in Azure Portal is still showing the version as 0.10.28.
What did I miss?
Turns out that 8.x was not a correct syntax.
I've changed it to 8.1.4 both in packages.json and in the Application Settings, and it worked.
I found the list of supported versions here:
https://MYSITE.scm.azurewebsites.net/api/diagnostics/runtime
I'm having issue while I'm installing MarkLogic. When I execute the command
npm install marklogic --save
I'm getting an error. It says
Refusing to install marklogic as a dependency of itself
package.json:
{
"name": "marklogic",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.15.1",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"express": "~4.13.4",
"jade": "~1.11.0",
"morgan": "~1.7.0",
"serve-favicon": "~2.3.0"
}
}
Checking -- if you cloned the MarkLogic Node.js API project, then ran the npm install command that you show above, I'd expect to see this error. Is that what's happening?
Edit: elevating #grtjn's point from the comment: When selecting a name for your package, it has to be unique. "marklogic" is the name of an existing package, and therefore conflicted with the same name used for the package you were building.