Error: Cannot find module 'dotenv' Sep 1 09:33:34 AM Require stack: Sep 1 09:33:34 AM - /opt/render/project/src/utils/cloudinary.js Sep 1 09:33:34 AM - /opt/render/project/src/controllers/handlerFactory.js Sep 1 09:33:34 AM - /opt/render/project/src/c

I am unsure of why dotenv file is causing the deployment to not run. I also added node version to the environments but this did not help either.

this is the package.json
{
“name”: “server”,
“version”: “1.0.0”,
“description”: “”,
“main”: “index.js”,
“scripts”: {
“start”: “node app.js”,
“startDev”: “nodemon app.js”
},
“keywords”: ,
“author”: “”,
“license”: “ISC”,
“dependencies”: {
“bcryptjs”: “^2.4.3”,
“cloudinary”: “^1.31.0”,
“cookie-parser”: “^1.4.6”,
“cors”: “^2.8.5”,
“express”: “^4.17.2”,
“html-to-text”: “^8.1.0”,
“joi”: “^17.5.0”,
“jsonwebtoken”: “^8.5.1”,
“lodash”: “^4.17.21”,
“mongoose”: “^6.1.5”,
“multer”: “^1.4.4”,
“nodemailer”: “^6.7.2”,
“pug”: “^3.0.2”,
“sharp”: “^0.29.3”,
“stripe”: “^8.195.0”,
“util”: “^0.12.4”,
“validator”: “^13.7.0”
},
“devDependencies”: {
“dotenv”: “^10.0.0”,
“nodemon”: “^2.0.15”
}
}

======================================================

this is the app.js

const env = process.env.NODE_ENV || ‘development’;
if(env === ‘development’){require(‘dotenv’).config();}

    const express = require('express');
    const app = express();
    const cors = require('cors');



    app.get("/", (req, res)=> (res.send("HIyaaaaaa")));

=================

this is the cloudinary file

require(“dotenv”).config();
const cloudinary = require(“cloudinary”).v2;

cloudinary.config({
cloud_name: process.env.CLOUDN,
api_key: process.env.CLOUDAPIKEY,
api_secret: process.env.CLOUDS
})

module.exports = cloudinary

Hi,

Your dotenv package is in the devDependencies group. I suspect you may have manually set NODE_ENV to “production” which means devDependencies wouldn’t be installed.

You can either move the package to your dependencies or tell npm install explicitly to install them with the --production=false option. npm install docs

Alan

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.