module: disable package self resolution when name contains a colon
There is a discrepancy between package self resolution in CJS and ESM contexts. This commit fixes this by forbidding self-resolution of packages whose names contain a colon.
Currently, ESM understands specifier with a column as a URL scheme (E.G.: file:package
references package
under the scheme file:
), while CJS interpret the specifier as a path, so the colon is just another valid character (I.E.: file:package
references a package named file:package
).
I think this should be considered as a bug fix and backported as far as we can, this is especially important considering it affects stuff like require('node:fs')
which should take a different meaning soon (see https://github.com/nodejs/node/pull/37246).
Note that while this is technically a breaking change, I'm confident it should not affect the ecosystem as npm already requires a name that doesn't contain colons (https://docs.npmjs.com/creating-a-package-json-file#required-name-and-version-fields), plus package self-resolution usually affects dev-env only.
/cc @nodejs/modules