Skip to content

add esm entry points for node #5167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 104 additions & 26 deletions packages-exp/firebase-exp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,107 +25,185 @@
],
"exports": {
"./analytics": {
"node": "./analytics/dist/index.cjs.js",
"node": {
"require": "./analytics/dist/index.cjs.js",
"import": "./analytics/dist/index.esm.js"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file extension should be .mjs, otherwise Node would fail to parse it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, good catch! I fixed it in a different way by declaring "type": "module" in the package.jsons, and changing the extension of cjs files from js to cjs, so they still work with require()s. This way, I only need to generate 2 files per subpath, an esm.js file and a cjs file instead of 3(esm.js, esm.mjs and cjs.js).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it locally, and both import and require syntax work with this setup.

},
"default": "./analytics/dist/index.esm.js"
},
"./app": {
"node": "./app/dist/index.cjs.js",
"node": {
"require": "./app/dist/index.cjs.js",
"import": "./app/dist/index.esm.js"
},
"default": "./app/dist/index.esm.js"
},
"./app-check": {
"node": "./app-check/dist/index.cjs.js",
"node": {
"require": "./app-check/dist/index.cjs.js",
"import": "./app-check/dist/index.esm.js"
},
"default": "./app-check/dist/index.esm.js"
},
"./auth": {
"node": "./auth/dist/index.cjs.js",
"node": {
"require": "./auth/dist/index.cjs.js",
"import": "./auth/dist/index.esm.js"
},
"default": "./auth/dist/index.esm.js"
},
"./auth/cordova": {
"node": "./auth/cordova/dist/index.cjs.js",
"node": {
"require": "./auth/cordova/dist/index.cjs.js",
"import": "./auth/cordova/dist/index.esm.js"
},
"default": "./auth/cordova/dist/index.esm.js"
},
"./auth/react-native": {
"node": "./auth/react-native/dist/index.cjs.js",
"node": {
"require": "./auth/react-native/dist/index.cjs.js",
"import": "./auth/react-native/dist/index.esm.js"
},
"default": "./auth/react-native/dist/index.esm.js"
},
"./database": {
"node": "./database/dist/index.cjs.js",
"node": {
"require": "./database/dist/index.cjs.js",
"import": "./database/dist/index.esm.js"
},
"default": "./database/dist/index.esm.js"
},
"./firestore": {
"node": "./firestore/dist/index.cjs.js",
"node": {
"require": "./firestore/dist/index.cjs.js",
"import": "./firestore/dist/index.esm.js"
},
"default": "./firestore/dist/index.esm.js"
},
"./firestore/lite": {
"node": "./firestore/lite/dist/index.cjs.js",
"node": {
"require": "./firestore/lite/dist/index.cjs.js",
"import": "./firestore/lite/dist/index.esm.js"
},
"default": "./firestore/lite/dist/index.esm.js"
},
"./functions": {
"node": "./functions/dist/index.cjs.js",
"node": {
"require": "./functions/dist/index.cjs.js",
"import": "./functions/dist/index.esm.js"
},
"default": "./functions/dist/index.esm.js"
},
"./messaging": {
"node": "./messaging/dist/index.cjs.js",
"node": {
"require": "./messaging/dist/index.cjs.js",
"import": "./messaging/dist/index.esm.js"
},
"default": "./messaging/dist/index.esm.js"
},
"./messaging/sw": {
"node": "./messaging/sw/dist/index.cjs.js",
"node": {
"require": "./messaging/sw/dist/index.cjs.js",
"import": "./messaging/sw/dist/index.esm.js"
},
"default": "./messaging/sw/dist/index.esm.js"
},
"./performance": {
"node": "./performance/dist/index.cjs.js",
"node": {
"require": "./performance/dist/index.cjs.js",
"import": "./performance/dist/index.esm.js"
},
"default": "./performance/dist/index.esm.js"
},
"./remote-config": {
"node": "./remote-config/dist/index.cjs.js",
"node": {
"require": "./remote-config/dist/index.cjs.js",
"import": "./remote-config/dist/index.esm.js"
},
"default": "./remote-config/dist/index.esm.js"
},
"./storage": {
"node": "./storage/dist/index.cjs.js",
"node": {
"require": "./storage/dist/index.cjs.js",
"import": "./storage/dist/index.esm.js"
},
"default": "./storage/dist/index.esm.js"
},
"./compat/analytics": {
"node": "./compat/analytics/dist/index.cjs.js",
"node": {
"require": "./compat/analytics/dist/index.cjs.js",
"import": "./compat/analytics/dist/index.esm.js"
},
"default": "./compat/analytics/dist/index.esm.js"
},
"./compat/app": {
"node": "./compat/app/dist/index.cjs.js",
"node": {
"require": "./compat/app/dist/index.cjs.js",
"import": "./compat/app/dist/index.esm.js"
},
"default": "./compat/app/dist/index.esm.js"
},
"./compat/app-check": {
"node": "./compat/app-check/dist/index.cjs.js",
"node": {
"require": "./compat/app-check/dist/index.cjs.js",
"import": "./compat/app-check/dist/index.esm.js"
},
"default": "./compat/app-check/dist/index.esm.js"
},
"./compat/auth": {
"node": "./compat/auth/dist/index.cjs.js",
"node": {
"require": "./compat/auth/dist/index.cjs.js",
"import": "./compat/auth/dist/index.esm.js"
},
"default": "./compat/auth/dist/index.esm.js"
},
"./compat/database": {
"node": "./compat/database/dist/index.cjs.js",
"node": {
"require": "./compat/database/dist/index.cjs.js",
"import": "./compat/database/dist/index.esm.js"
},
"default": "./compat/database/dist/index.esm.js"
},
"./compat/firestore": {
"node": "./compat/firestore/dist/index.cjs.js",
"node": {
"require": "./compat/firestore/dist/index.cjs.js",
"import": "./compat/firestore/dist/index.esm.js"
},
"default": "./compat/firestore/dist/index.esm.js"
},
"./compat/functions": {
"node": "./compat/functions/dist/index.cjs.js",
"node": {
"require": "./compat/functions/dist/index.cjs.js",
"import": "./compat/functions/dist/index.esm.js"
},
"default": "./compat/functions/dist/index.esm.js"
},
"./compat/messaging": {
"node": "./compat/messaging/dist/index.cjs.js",
"node": {
"require": "./compat/messaging/dist/index.cjs.js",
"import": "./compat/messaging/dist/index.esm.js"
},
"default": "./compat/messaging/dist/index.esm.js"
},
"./compat/performance": {
"node": "./compat/performance/dist/index.cjs.js",
"node": {
"require": "./compat/performance/dist/index.cjs.js",
"import": "./compat/performance/dist/index.esm.js"
},
"default": "./compat/performance/dist/index.esm.js"
},
"./compat/remote-config": {
"node": "./compat/remote-config/dist/index.cjs.js",
"node": {
"require": "./compat/remote-config/dist/index.cjs.js",
"import": "./compat/remote-config/dist/index.esm.js"
},
"default": "./compat/remote-config/dist/index.esm.js"
},
"./compat/storage": {
"node": "./compat/storage/dist/index.cjs.js",
"node": {
"require": "./compat/storage/dist/index.cjs.js",
"import": "./compat/storage/dist/index.esm.js"
},
"default": "./compat/storage/dist/index.esm.js"
}
},
Expand Down