Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use global.require to silence webpack warning #3129

Merged
merged 10 commits into from Jun 23, 2019
Merged

Use global.require to silence webpack warning #3129

merged 10 commits into from Jun 23, 2019

Conversation

mischnic
Copy link
Member

@mischnic mischnic commented Jun 4, 2019

↪️ Pull Request

I'm still not quite sure whether module.require and require are completely equivalent. Doing toString in node show this:

module.require = function(id) {
  validateString(id, 'id');
  if (id === '') {
    throw new ERR_INVALID_ARG_VALUE('id', id, 'must be a non-empty string');
  }
  return Module._load(id, this, /* isMain */ false);
};

global.require = function(path) {
  try {
    exports.requireDepth += 1;
    return mod.require(path);
  } finally {
    exports.requireDepth -= 1;
  }
};

Related: #2883

@mischnic mischnic changed the title Use module.require to silence webpack warning Use global.require to silence webpack warning Jun 4, 2019
@mischnic
Copy link
Member Author

mischnic commented Jun 5, 2019

Mh, is typeof global.require === "function" needed as well?

@devongovett
Copy link
Member

I don’t think require is actually a global in node right? It wraps modules in a closure with a require argument, just like parcel does. So checking global.require probably won’t work.

@mischnic
Copy link
Member Author

mischnic commented Jun 9, 2019

You're right...
But module.require and require are slightly different.

@devongovett
Copy link
Member

Should we check that both module.require and require exist, but actually call require?

@mischnic
Copy link
Member Author

mischnic commented Jun 9, 2019

but actually call require?

No, because of the original issue with typeof require === 'function' && require: Webpack can infer that nodeRequire is require and tries to bundle that call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants