Skip to content

global variable is not available in the module #181

@bugy

Description

@bugy

Hi, I'm trying to add a non-exported 3rd party class to global scope, using rewire

The class looks like this: https://github.com/Dogfalo/materialize/blob/v1-dev/js/component.js

I'm doing it this way:

const ComponentModule = require('rewire')('materialize-css/js/component');
global.Component = ComponentModule.__get__('Component');

And it almost works, but inside component.js, there are usages of Element and cash. And during runtime, they fail as "is not defined"

I managed to solve the problem by:

const ComponentModule = require('rewire')('materialize-css/js/component');
ComponentModule.__set__('Element', Element);
ComponentModule.__set__('cash', cash);

global.Component = ComponentModule.__get__('Component');

And it works.

However, it seems very strange to me, since both of these variables are available before rewiring. Is there any way to add these globals implicitly?

I think it might be the same problem: #99

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