Skip to content

Fix issue #87 - Error: unexpected top-level await with Node 23 ESM - #90

Merged
pioug merged 1 commit into
nfroidure:mainfrom
timint:main
Apr 26, 2025
Merged

pioug merged 1 commit into
nfroidure:mainfrom
timint:main

Conversation

@timint

@timint timint commented Dec 30, 2024

Copy link
Copy Markdown
Contributor

No description provided.

@pioug
pioug merged commit b2f57fb into nfroidure:main Apr 26, 2025
@perrin4869

Copy link
Copy Markdown
Contributor

can this be released to npm? thanks!

@nfroidure

Copy link
Copy Markdown
Owner

@perrin4869 tbh, I am not sure it is a good thing. The point of the dynamic imports were to avoid importing unused code (depending on the fact you choose to use one module over another). This change introduce the import of both which is probably not what we want and may break some priori usages of this module. Would be nice to have more input from @timint and @pioug and their thinking about it before pushing a new version. Maybe that we could ship a beta module first.

@nfroidure

Copy link
Copy Markdown
Owner

Also, I couldn't dive in further yet, but I thought that top level awaits were supposed to work in recent node versions. Has it changed for new node one and why?

@pioug

pioug commented May 22, 2025

Copy link
Copy Markdown
Collaborator

I think it’s best to make this fix available to everyone. There’s not much activity in the project now, so while people are still willing to report and fix issues, I think it’s okay to go along before an alternative comes up or people stop caring.

Importing unused code may not be a big deal for this type of tool (and we can always optimize it again in the future). There’s a chance it could break existing usage, but versioning can cover us, and again, I feel like it's more important to make it work for people who are in updated/recent environments.

I was thinking about bumping a major version. I’m worried that we won’t get enough exposure from a beta release. A beta release would still require work upstream to get the beta version.

I’m sorry for merging the PR without your approval 🙈

About top-level awaits, it seems like the mix of CJS and ESM can cause problems. Running just the lib works fine, but I can imagine some issues when adding in Gulp and Gulp plugins.

@nfroidure

Copy link
Copy Markdown
Owner

@pioug Thanks for your reply, make sense to me. I just published ttf2woff2@7.0.0 then. Have a nice day

@perrin4869

Copy link
Copy Markdown
Contributor

some additional insight:
in my case, the problem was caused because of fontfacegen, which unfortunately I haven't yet updated to use esm, and was using require to import ttf2woff2 here.

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

Successfully merging this pull request may close these issues.

4 participants