Created
December 5, 2022 05:01
-
-
Save tyhopp/4e13f681d385237959a150b01bd53871 to your computer and use it in GitHub Desktop.
await-import-conditional-cjs-exports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myModule = await import(`./other.cjs`); | |
// Running node index.mjs writes this out to stdout, top-level `other` property is undefined: | |
// [Module: null prototype] { | |
// default: { hello: [Function: hello] }, | |
// hello: [Function: hello], | |
// other: undefined | |
// } | |
console.log(myModule); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hello() { | |
console.log(`world`); | |
} | |
exports.hello = hello; | |
const shouldInclude = false; | |
if (shouldInclude) { | |
exports.other = `other`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment