-
Notifications
You must be signed in to change notification settings - Fork 23
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
gh-43: Fix ESModule incompatibility with node16 #46
base: main
Are you sure you want to change the base?
Conversation
To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge. |
I agree to the CLA 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hey @parkerduckworth, I'm sorry but changes in Here are a few thoughts:
So according to the doc,
Now lets go to the typescript documentation and take a look at how this field should be used. From the official typescript documentation:
Let me add to the last quote. You've probably seen some packages avoid this rule, for example Firebase SDK has one declaration file for set of conditions and use FinallySince you have a ...
"exports": {
".": {
"import": {
"types": "./dist/index.esm2020.d.mts",
"default": "./dist/index.esm2020.mjs"
},
"default": {
"types": "./dist/index.cjs.d.ts",
"default": "./dist/index.cjs.js"
}
}
},
// fallback for older environment
"main": "./dist/index.cjs.js",
"types": "./dist/index.cjs.d.ts",
// you can leave it for older bundlers support
"module": "./dist/index.esm2020.mjs",
... This solution is not easy to implement because you don't really have CC: #43 |
@iSuslov is probably right, and I appreciate all the details provided. Some of it might’ve gone over my head during my brief look at it, though, so I will try the new v1.3 myself, and will report specific actionable findings on Monday or Tuesday. I haven’t had a chance to work with it yet. |
@maxilie @iSuslov I am totally fine with whichever solution fixes this problem. We can stop using tsup as well, if there are better alternatives. The only concern is to maintain backwards compatibility with existing cjs projects which use this client. If we can maintain that while making this package type |
@parkerduckworth I can confirm that v1.3.0 fixes my issues, but my setup isn't 100% conventional. I suggest merging @iSuslov's PR since it's based on the latest version and it just tweaks a couple of lines to conform to the typescript docs -- and it seems to add more stability and support for a wider variety project setups than the current v1.3.0. I don't think the details of my project configurations are relevant, but I'll list them here in case it's helpful... My First Project:
My Second Project:
|
Add compatibility with packages defined as ES Modules.
The Problem:
module
field ormoduleResolution
field intsconfig.json
is es16, esnext, es6, etc.) cannot resolve the type of the default export inindex.ts
because it uses the CommonJS format (exports.default =
) which ES Modules don't recognize.export default ...
format that ES Modules recognize, then the type definitions will resolve properly but the import will fail at runtime since weaviate was still built as a CommonJS module.Changes Made:
.d.ts
type definitions and.js
output to the same/dist
directory.build.js
&test.js
to.cjs
).Effects:
I'm not sure if this could break things. I ran the tests and have been using this code in my own project, in Typescript. I haven't tried to use it in JavaScript but I won't be surprised if JavaScript users will need to replace their
require()
s with dynamicimport()
s and change their.js
files to.cjs
.If some people are actually using javascript and you don't want to burden them with dynamic imports, then I'm not sure of a good solution for this. The community is moving over to ES Modules, and the typescript devs don't plan to add support for this problem with default exports.