Skip to content

Commit

Permalink
Add exports within package.json to enable scoped package loading.
Browse files Browse the repository at this point in the history
In order for module resolution to work with .mjs or package: module code
we need to utilize the conditional export feature of node.

> The current specifier resolution does not support all default behavior of the CommonJS loader. One of the behavior differences is automatic resolution of file extensions and the ability to import directories that have an index file.

https://nodejs.org/api/esm.html#esm_customizing_esm_specifier_resolution_algorithm
https://nodejs.org/api/packages.html#packages_conditional_exports

This directly enables rxjs to work with mjs code and commonjs code since
mjs does not support loading bare folder paths.

This is a fix to:
sveltejs/kit#612

and is directly related to the conversation in this issue within node
core nodejs/node#27408
  • Loading branch information
samccone committed Mar 29, 2021
1 parent c41f65b commit 7ca6512
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
"es2015": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"sideEffects": false,
"exports": {
".": {
"node": "./dist/cjs/index.js",
"default": "./dist/esm5/index.js"
},
"./operators": {
"node": "./dist/cjs/operators/index.js",
"default": "./dist/dist/esm5/operators/index.js"
},
"./package.json": "./package.json"
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
Expand Down

0 comments on commit 7ca6512

Please sign in to comment.