Skip to content
Advertisement

Deprecated message: “Auto import from ‘process’ (property) NodeJS.Process.mainModule?: NodeJS.Module NodeJS.Module ‘mainModule’ is deprecatedts”

I’m trying to use mainModule like this:

const { mainModule } = require('process');
module.exports = path.dirname(mainModule.filename);

But I’m receiving the following messages:

const mainModule: NodeJS.Module ‘mainModule’ is deprecatedts(6385)

Auto import from ‘process’ (property) NodeJS.Process.mainModule?: NodeJS.Module

@deprecated — since v14.0.0 – use require.main instead.

How can I Solve this?

Advertisement

Answer

I found here that you just need to change this:

const { mainModule } = require('process');
module.exports = path.dirname(mainModule);

To this:

module.exports = path.dirname(require.main.filename);
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement