Issues with import into es6 project
See original GitHub issueI’ve pulled this into my project from NPM and I’m trying to import it into a webcomponent but
import { humanizeDuration } from 'humanize-duration/humanize-duration.js';
gives an error that there is not export named humanizeDuration
So I tried
import 'humanize-duration/humanize-duration.js';
but this gives an error Uncaught (in promise) TypeError: Cannot set property 'humanizeDuration' of undefined
from the following line 1118 code
humanizeDuration.humanizer = humanizer;
if (typeof define === 'function' && define.amd) {
define(function () {
return humanizeDuration;
});
} else if (typeof module !== 'undefined' && module.exports) {
module.exports = humanizeDuration;
} else {
this.humanizeDuration = humanizeDuration;
}
})(); // eslint-disable-line semi
basically the last line of real code in the above snippet.
Any ideas how to get around it?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:22 (10 by maintainers)
Top Results From Across the Web
Avoid these issues when using new ECMAScript modules in ...
If you observe an issue with your published module where a tool can't import modules from it correctly then you probably missed setting...
Read more >ES6 Modules and How to Use Import and Export in JavaScript
You can export members one by one. What's not exported won't be available directly outside the module: export const myNumbers = [1 ...
Read more >16. Modules - Exploring JS
The imports of an ES6 module are read-only views on the exported entities. That means that the connections to variables declared inside module...
Read more >Upgrade your Node app: From CommonJS to ES Modules
Most changes are small, but there're a lot of them. It will take a while to adjust all exports and imports and your...
Read more >Unable to import module in nodejs using ES6 Modules
Did you try running that function in an async context? For instance: import { connectMongoDB } from "./config/db"; (async () => { await ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Revisiting this, it seems like Node is still working on ES module support. Is anyone aware of the best practices here?
Sindre Sorhus has been moving his packages to pure ESM.