-
Notifications
You must be signed in to change notification settings - Fork 56
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
Understand why ably/modules
is causing an "unexpected module syntax" error in npx attw
#1546
Comments
…-into-v2 I’ve worked around the `attw` error that this introduces because I wasn’t able to solve it quickly; have created #1546 for doing so.
➤ Automation for Jira commented: The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3994 |
The error comes from Node.js not being able to correctly resolve our The fully correct solution would be to change output file extension for "exports": {
"./modules": {
"types": "./modules.d.mts",
"module": "./build/modules/index.mjs"
"import": "./build/modules/index.mjs"
}
} Which would indicate that The main issue with this solution is changing generation rules for A better solution for now, rather than completely ignoring the "Unexpected module syntax" error (which is quite vague), might be the following: "exports": {
"./modules": {
"types": "./modules.d.ts",
"module": "./build/modules/index.mjs"
"import": "./build/modules/index.mjs"
}
}, This way we avoid tinkering with @lawrence-forooghian let me know what you think |
I'm not sure I understand why switching the extension of Also, what does the |
Took one more look, it seems like the docs use it only when "require" condition is also present. Based on this explanation, it does seem to provide some bundle step optimization for Node.js, if those bundlers can resolve ES modules via Since we don't provide CommonJS module for
Switching to To solve this, declaration files would need to be auto-generated using tsc (esbuild doesn't support outputting declaration files), but then we run into issues of combining declaration files into one (tsc doesn't allow it for ESM) and still doesn't guarantee that issue would be resolved, since js would be generated by esbuild, and .d.mts files by tsc. |
So, if I've understood correctly, in order to get I still don't understand, however, why doing this means that we must switch to using auto-generated declaration files. The "internal resolution error" page describes a bunch of reasons why this error might occur. My reading of that page is that, if you use hand-written declaration files and those files, for some reason, don't match (the exact kinds of mismatch that might trigger the error not clear to me) what's in the JavaScript bundle, then you will get this error. So, perhaps it's worth spending some time to try and understand what is the mismatch that’s causing this error, and maybe we can just fix that? (By the way, I fully agree that being able to switch to automatically generating the declaration files would be a good thing. The main challenge there — in addition to what you mentioned — is making sure that doing so wouldn't change our shipped type declarations in a way that changes the declared public API of the SDK. Because, currently, our public API is what's contained in the type declaration files, not the types contained in the implementation. And these types don't always match — they should, but they don’t. So we'd need to go through a process of aligning them first.) |
Yes, and in this case, we would need to fix the "Internal resolution error" emitted by
This is exactly it.
And here is a troubled part. Also "mismatch" can be a really convoluted issue. There was an issue I fixed in v2 branch with imports in react hooks #1619 - we were imporing typings from ably using
Now the problem with that, is that auto generated type declaration files for ESM are not bundlable. You cannot concatenate them in a single file, it is just not supported for ESM specifically. So even that by itself can be a reason why So, by simply changing |
Thanks for the explanation. Let's go with your suggestion then. |
Fixed in #1696 |
For now I've disabled this check, but would be good to understand. One way to fix it is to change the
exports."./modules".default
inpackage.json
toexports."./modules".browser
(i.e. to not advertise this package to Node), but according to this documentation we should have adefault
field, for future browser-like environments.┆Issue is synchronized with this Jira Bug by Unito
The text was updated successfully, but these errors were encountered: