Skip to content

module undefined in require.cache when it's kept. #4

@jasperjn

Description

@jasperjn

Hi
My project launched failed after request-promise update to v4.2.1. The error message indicates that require.cache got undefined with several keys when I try to iterate objects in requird.cache.
References:
request/request-promise@fdc522a
Because tough-cookie has not been required, tough-cookie does not exist in originalCache. It'll assign undefined with keys in the modulesToKeep on the next line.
https://github.com/analog-nico/stealthy-require/blob/master/lib/index.js#L71

Example

var webpack = require('webpack');
var stealthyRequire = require('./index');

var newWebpack = stealthyRequire(require.cache, function () {
    return require('webpack');
}, function () {
    require('tough-cookie');
}, module);

Object.keys(require.cache).forEach(key => {
    if (!require.cache[key]) {
        // tough-cookies and it's dependencies undefined. But key is still there.
    }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions