commonjs-assert icon indicating copy to clipboard operation
commonjs-assert copied to clipboard

Ambiguous Package Name

Open georg-schwarz opened this issue 1 year ago • 1 comments

We stumbled upon the issue of ambiguous imports when using this library. require(assert) can refer to the library or Node's assert API.

It would be awesome to have the library available under a second name (e.g., assert.js) in use cases where you don't want to have this ambiguity. Other libraries with the same issue went down a similar road, e.g. punycode.

Original thread: https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2326

georg-schwarz avatar May 08 '24 12:05 georg-schwarz

in node, require of “assert” will always only be the core module. There’s no ambiguity.

If you want to refer to this package, you require “assert/“. For native ESM, there’s not a good solution there, as indicated in the linked issue.

In browsers when using a bundler, this package is transparently used instead of the node core module, which is the point.

When would you want to use this package directly such that you need to disambiguate?

ljharb avatar May 08 '24 14:05 ljharb