Skip to content

module: package imports targets outside package

this allows the imports field of package.json to target a location outside of the package boundary. doing so allows for imports to work in directories just altering things like the type field of package.json and to enable monorepo workspace workflows.


Node already allows resolving to external packages for "imports"; this fixes some usability problems of mixing monorepos and directories containing a {"type":"module"} (or vice versa) package.json preventing the ability to properly use "imports" to resolve to reasonable locations. It does not enable .. in a specifiers to escape still per the tests it must be in the target of the package.json to allow escaping.

An example of a case where this feature is high friction is:

/app/package.json => {"type":"module","imports": ...}
/app/bin/package.json => {"type":"commonjs"} -- cannot use any "imports", even if redeclared in /app/bin

Note: this still requires duplication of imports for this use case with this PR.

Another example is in a monorepo situation:

/app/lib
/app/workspaces/a -- cannot reference /app/lib using "imports"

Merge request reports

Loading