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

Will require fail if imported as an ES module in Node? #1

Closed
mrjacobbloom opened this issue Oct 23, 2019 · 3 comments
Closed

Will require fail if imported as an ES module in Node? #1

mrjacobbloom opened this issue Oct 23, 2019 · 3 comments
Labels
bug Something isn't working

Comments

@mrjacobbloom
Copy link
Owner

Would we need to use createRequire? Can we circumvent this since new Node should be able to use Symbol.for(...)?

@mrjacobbloom
Copy link
Owner Author

@mrjacobbloom
Copy link
Owner Author

Should look something like

const isNode = typeof process !== undefined;
let symbolInspect;
if(isNode) {
  if (typeof require === 'undefined') {
    symbolInspect = Symbol.for('nodejs.util.inspect.custom');
  } else {
    try {
      symbolInspect = require('util').inspect.custom;
    } catch {}
  }
}

@mrjacobbloom
Copy link
Owner Author

mrjacobbloom commented Feb 27, 2020

The shared symbol was introduced in Node 10.12. 10 is in LTS and hits maintenance LTS on April 1. I think we can safely drop the require('util') in favor of

const symbolInspect = isNode ? Symbol.for('nodejs.util.inspect.custom') : null;

@mrjacobbloom mrjacobbloom mentioned this issue Feb 27, 2020
3 tasks
@mrjacobbloom mrjacobbloom added the bug Something isn't working label Feb 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant