question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues with import into es6 project

See original GitHub issue

I’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:open
  • Created 4 years ago
  • Reactions:2
  • Comments:22 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
EvanHahncommented, Feb 20, 2020

Revisiting this, it seems like Node is still working on ES module support. Is anyone aware of the best practices here?

1reaction
dasacommented, Jul 20, 2021

Sindre Sorhus has been moving his packages to pure ESM.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found