Skip to content
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

ES module import issue #202

Closed
andyzaharia opened this issue Sep 14, 2022 · 19 comments
Closed

ES module import issue #202

andyzaharia opened this issue Sep 14, 2022 · 19 comments
Assignees

Comments

@andyzaharia
Copy link

andyzaharia commented Sep 14, 2022

Hi guys, newbie JS developer here.

I've been using this framework in a nodejs app for quite a while and decided to update the server to use ES modules. All went great with all the dependencies that I had in the project but when I got to import the encode func, nodejs complains about the package being a CommonJS module, even thou... I don't think thats true.

import { encode } from "blurhash"; - this ends up with a _SyntaxError: Named export 'encode' not found. The requested module 'blurhash' is a CommonJS module... _ erorr

and if I do this:

import blurhash from "blurhash"; - I end up with a SyntaxError: Unexpected token 'export' error.

Does anyone have any idea what this happens?

Thanks a lot and sorry of this is a stupid question.

Later edit: This problems seems to be happening only with the 2.0.0 version, the 1.1.5 works fine.

syuilo added a commit to misskey-dev/misskey that referenced this issue Sep 19, 2022
@syuilo
Copy link

syuilo commented Sep 19, 2022

I have the exact same issue.
I have tried importing dist/esm/index.js directly, etc., but no matter how I try, I can't solve the issue.

@kadengeyaa
Copy link

This seems to be a problem in blurhash package.json.

To fix it, I had to edit node_modules/blurhash/package.json and added the line:
"type": "module"

Then you can use object deconstruction to import blurhash

import { encode } from 'blurhash'

@Thisen
Copy link
Collaborator

Thisen commented Sep 22, 2022

I'll look into this, when I have some time.

@davedbase
Copy link

Confirmed, similar issue here. I'm writing a Vite plugin that leverages blurhash and get:

import { encode } from "blurhash";
         ^^^^^^
SyntaxError: Named export 'encode' not found. The requested module 'blurhash' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'blurhash';
const { encode } = pkg;

The issue is detailed above but I thought provide the exact issue as seen with my bundler.

I reverted to 1.1.3 which has the correct export. Using 2.0.0 is blocked until the export detailed above is resolved.

Thanks for maintaining this neat project.

@Thisen
Copy link
Collaborator

Thisen commented Sep 27, 2022

Hi all 👋🏼

Please try out 2.0.1 and let me know if that resolves your issues.

@arpowers
Copy link

arpowers commented Sep 27, 2022

@Thisen am using 2.0.1 and same issue.

Looks like is still loading the CJS version in Vite, giving error: 'module' is not defined or the does not provide export one above.

@Thisen
Copy link
Collaborator

Thisen commented Sep 27, 2022

@Thisen am using 2.0.1 and same issue.

Looks like is still loading the CJS version in Vite, giving error: 'module' is not defined or the does not provide export one above.

Could you provide me with a reproduction?

@arpowers
Copy link

@Thisen sure...
https://github.com/kaption-co/blurhash-repro

Note that this repro excludes 'blurhash' from optimizing the default CJS file to ESM...

@Thisen
Copy link
Collaborator

Thisen commented Sep 28, 2022

@Thisen sure... https://github.com/kaption-co/blurhash-repro

Note that this repro excludes 'blurhash' from optimizing the default CJS file to ESM...

Thank you for the reproduction! It helped me to resolve the issue and it should work in 2.0.2. Please try it out.

mrtnzlml added a commit to adeira/universe that referenced this issue Sep 28, 2022
It seems to be currently broken (and 2.0.2 doesn't seem to be working either), see: woltapp/blurhash#202
kodiakhq bot pushed a commit to adeira/universe that referenced this issue Sep 29, 2022
It seems to be currently broken (and 2.0.2 doesn't seem to be working either), see: woltapp/blurhash#202
adeira-github-bot pushed a commit to adeira/sx-design that referenced this issue Sep 29, 2022
It seems to be currently broken (and 2.0.2 doesn't seem to be working either), see: woltapp/blurhash#202

adeira-source-id: c28a421e4a6e5e49bff6d071454ac1474b754896
@Thisen
Copy link
Collaborator

Thisen commented Oct 3, 2022

@Thisen sure... https://github.com/kaption-co/blurhash-repro
Note that this repro excludes 'blurhash' from optimizing the default CJS file to ESM...

Thank you for the reproduction! It helped me to resolve the issue and it should work in 2.0.2. Please try it out.

#210 pointed out in exports field order, try 2.0.3. 💪🏼

@Thisen
Copy link
Collaborator

Thisen commented Oct 3, 2022

@mrtnzlml I see you had some issues, could you try out 2.0.3? :)

@arpowers
Copy link

arpowers commented Oct 3, 2022

@Thisen this is resolved for me in latest version.

@Thisen
Copy link
Collaborator

Thisen commented Oct 4, 2022

Awesome! Closing.

@Thisen Thisen closed this as completed Oct 4, 2022
@mrtnzlml
Copy link

mrtnzlml commented Oct 6, 2022

Hi @Thisen! 👋 There is still some breaking change in the patch release, as you can see in this PR: adeira/universe#5088

The situation got better. I can start the application with blurhash 2.0.3; however, it's still failing in Jest tests. 😞

@Thisen
Copy link
Collaborator

Thisen commented Oct 10, 2022

Hi @Thisen! 👋 There is still some breaking change in the patch release, as you can see in this PR: adeira/universe#5088

The situation got better. I can start the application with blurhash 2.0.3; however, it's still failing in Jest tests. 😞

I can't speak into that. I'd need a new issue with a reproduction :)

@janpe
Copy link

janpe commented Oct 14, 2022

Hi @Thisen! 👋 There is still some breaking change in the patch release, as you can see in this PR: adeira/universe#5088

The situation got better. I can start the application with blurhash 2.0.3; however, it's still failing in Jest tests. 😞

I'm seeing this as well. Jest tests break at 2.0.3. @mrtnzlml did you find a workaround?

@janpe
Copy link

janpe commented Oct 14, 2022

Ok I see that adding blurhash into transformIgnorePatterns in Jest config is a workaround for this bug. Not sure where this happens but it seems like a bug in this project @Thisen

@Thisen
Copy link
Collaborator

Thisen commented Oct 17, 2022

Ok I see that adding blurhash into transformIgnorePatterns in Jest config is a workaround for this bug. Not sure where this happens but it seems like a bug in this project @Thisen

A new issue with a reproduction would be great. 👍🏼

@mrtnzlml
Copy link

@janpe I didn't have time to check it yet or prepare a repro. Thanks for the suggested workaround! 👏 It is certainly a breaking change in a patch release. 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants