-
Notifications
You must be signed in to change notification settings - Fork 175
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
Issues with import into es6 project #153
Comments
This seems like an issue with how CommonJS imports are being rewritten with Does |
Fair shout, I gave it a try and this was the result |
Are you using anything to transpile ES6 imports to be compatible with CommonJS exports?
|
It's a polymer app, so currently just running with |
Okay. Are you able to import any other CommonJS modules this way? |
I seem to remember having similar issues with time-elements that I also use, but I think they now have two versions and modern one and a legacy. |
Could you try writing a simple CommonJS module and using it? Here's a simple one: module.exports = function () {
return 'Hello world!'
} My guess is that this isn't a problem with Humanize Duration but instead a problem with some module setup. |
Hmmm I just found this PWA Stater Kit FAQ maybe it just needs a ESM. I'll have a play with script tags and see if I can make it work. |
@RobMaskell see #159 |
Thanks @andrew-c-tran I'll check this out at the weekend when I have a little more time |
Ok I tried and changed my imports as follows
I get the following error
it doesn't like the line
|
@RobMaskell I suspect this is an issue with your build setup. How are you bundling dependencies? |
I call |
It might make sense for us to start publishing an ES module version (sorta like lodash-es).
Are you aware of precedent for that? I want to make sure to maintain backwards compatibility but also want to support ES modules.
|
I had the same problem back in the day with https://github.com/github/time-elements and then I think they sorted it in a new version, might be worth a look? |
Looks like they publish two exports and use the not-standard-but-used |
Node has an official recommendation not to publish ES modules right now. That may change in the future, but for now, I think I'm going to do nothing. |
But it can be used on frontend without node as well... |
True, but I'd prefer to only ship one thing. I fear that in trying to address some use cases (eg, a browser build that wants ECMAScript modules) I could break some other cases (eg, a setup that expects CommonJS).
I think I'd like to wait for Node to have a recommendation before continuing here.
|
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. |
This kind of import works correctly when using Vite + TypeScript: import humanizeDuration, { HumanizerOptions } from "humanize-duration" The |
Looks like a dead link from here. |
@MagnusOxlund @dasa Sindre's blog post was removed (why?), here's an archive: https://archive.is/5zMdR |
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 namedhumanizeDuration
So I tried
import 'humanize-duration/humanize-duration.js';
but this gives an errorUncaught (in promise) TypeError: Cannot set property 'humanizeDuration' of undefined
from the following line 1118 codebasically the last line of real code in the above snippet.
Any ideas how to get around it?
The text was updated successfully, but these errors were encountered: