'module is not defined in ES module scope

I try to update my code because I update nodejs from 8.12.0 to 16.14.0 and use es6.This my code before I got update nodejs.

const encryptRequestHeader = () => {
    if (module.exports._request == null) module.exports._request = {header: () => {return null;}};
    if (module.exports._request.encryptedUserNameLogin == null)
        module.exports._request.encryptedUserNameLogin = cryptoUtils.encrypt(module.exports._request.header('user-name-login'));
    if (module.exports._request.encryptedSimrNumber == null)
        module.exports._request.encryptedSimrNumber = cryptoUtils.encrypt(module.exports._request.header('sim-r-number'));
    if (module.exports._request.encryptedCustomerMobileNumber == null)
        module.exports._request.encryptedCustomerMobileNumber = cryptoUtils.encrypt(module.exports._request.header('customer-mobile'));
    if (module.exports._request.token == null)
        module.exports._request.token = module.exports._request.header('x-authorization');
    if (module.exports._request.token != null && module.exports._request.token.length > 20)
        module.exports._request.token = module.exports._request.token.slice(-20);
};

and this my code after i update nodejs.

const encryptRequestHeader = () => {
    if (exports._request == null)exports._request = {header: () => {return null;}};
    if (exports._request.encryptedUserNameLogin == null)
        exports._request.encryptedUserNameLogin = cryptoUtils.encrypt(exports._request.header('user-name-login'));
    if (exports._request.encryptedSimrNumber == null)
        exports._request.encryptedSimrNumber = cryptoUtils.encrypt(exports._request.header('sim-r-number'));
    if (exports._request.encryptedCustomerMobileNumber == null)
        exports._request.encryptedCustomerMobileNumber = cryptoUtils.encrypt(exports._request.header('customer-mobile'));
    if (exports._request.token == null)
        exports._request.token = exports._request.header('x-authorization');
    if (exports._request.token != null && exports._request.token.length > 20)
        exports._request.token = exports._request.token.slice(-20);
};

so now i try to run this code and it got error like this.

 if (exports._request == null)exports._request = {header: () => {return null;}};
    ^

ReferenceError: exports is not defined

what should I do if I don't want to remove "type": module because I want to use import like this in my project

import fs from 'fs';
import path from 'path';
import split from 'split';
import moment from 'moment';


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source