profile
viewpoint

Ask questionsProposal: Support loading package by own "name"

This has been discussed before, but I think it's a good time to consider it now.

A very common problem in Node.js applications is the backtracking problem where you have to always reference modules through ../../components/name.js.

Since we're loading the package.json when checking the module boundary, we thus also know the package.json "name" that any given module is in.

What we could do is support loading a package by its own package.json "name" by default.

This would allow conventions where users just set a package.json name and can then use import "pkgname/components/name.js" instead.

It's a very small feature that seems like it could solve a pain point quite elegantly.

Would be nice to discuss this further at the next meeting.

nodejs/modules

Answer questions robpalme

@ljharb You've mentioned this approach a few times now. What is the rationale for keeping CJS up to date with the ESM features?

It seems odd to try to update the old system to keep feature parity with features of the new system. Potentially it sends mixed messages about the future endorsed practices and places an ongoing tax on the design space.

useful!

Related questions

Transition Path Problems For Tooling hot 1
JSON modules are being reverted on web hot 1
Out-of-Band Meeting Proposal hot 1
node v13.0-v13.1 errors on require of a module with "exports" defined hot 1
Use consistent error codes for MODULE_NOT_FOUND hot 1
Out-of-Band Meeting Proposal hot 1
Loader Hooks hot 1
Github User Rank List