Node.js ReferenceError: process is not defined

Hi all,

Since I deployed a new version of my Node.js application the ‘process’ object seems to be undefined:

ReferenceError: process is not defined
at Object.<anonymous> (/usr/src/app/app.js:15:11)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

I can’t see any change in my application which could have caused this issue. start script in package.json is ‘node app.js’. I’m using the process object to read the environment variables.

Does anybody know what could have caused this issue?

Cheers,
Marco

Hi, can you please share relevant piece of code please?

Code is:

const request = require('./request');
const fs = require("fs");
const firebase = require('@firebase/app').default;
require('@firebase/firestore');

const lastUpdateFile = '/data/lastupdate.txt';
const assetDir = '/data/assets_import/';
const ip = 'localhost';

// const lastUpdateFile = './lastupdate.txt';
// const assetDir = './assets_import/';
// const ip = '192.168.1.106';

const firebaseConfig = {
apiKey: process.env.APIKEY,
authDomain: process.env.AUTHDOMAIN,
databaseURL: process.env.DATABASEURL,
projectId: process.env.PROJECTID,
storageBucket: process.env.STORAGEBUCKET,
messagingSenderId: process.env.MESSAGINGSENDERID,
}

const cbid = process.env.CBID;
const cfDomain = process.env.CFDOMAIN;

Basically the error is shown on the very first usage of process.env.*:

apiKey: process.env.APIKEY,

Thanks for your support on this!

I finally found the issue. Later on in the code I had a function named ‘process’ :man_facepalming:

Renaming this function solved the issue.

instead of process what we have to replace.i am using server.js, same error is getting for me.

Hi,
The issue here was that a custom function was called process which shadowed the imported process object. So it depends on your source code.

what you have renamed instead of process macro

Hey Yamini, process is a global variable in nodeJs, if you have instantiated a similar named variable/function in your code then you should rename that, it doesn’t matter what you rename it to.

Hey, I don’t know if any of you will be doing something stupid like me. But still, I am sharing this here. I came to this page because of the same issue. But later I found out that my mistake was using a capital P ‘Process’ instead of ‘process’. So checkout one again may you have the same issue.