Open xnuk opened 1 year ago
This is because they are shipping Common.js code, and module.exports exporting 1 object with all the values on it.
The docs are incorrect - to import this in a esm project you need to do this:
import Proto from '@proto/api'
const { BskyAgent } = Proto
likely the docs are incorrect because they are using typescript with "allowSyntheticDefaultImports": true,
- which is something you can use to make this syntax work.
This lib should be ideally be updated to ship both esm and cjs and have an exports property in the package.json:
"exports": {
".": {
"import": "./dist/my-lib.js",
"require": "./dist/my-lib.umd.cjs"
}
}
This error generating way of importing the API is still mentioned in the API readme’s on this repo and on NPM. Would be nice to change this so that new devs can onboard more quickly (and spare the “I am going nuts?!” thoughts) 🙂.
Does this issue still need to be looked at? I'm a first time open sourcer and would love to contribute! @xnuk
Does this issue still need to be looked at? I'm a first time open sourcer and would love to contribute! @xnuk
@pbaner16 Yes, I still can reproduce this in node v21.4.0 and @atproto/api 0.7.2.
If folks have a recommendation for small changes to the package README which would reduce confusion around this, i'd be interested to review! Unlike others on the team, i'm not a very experience Typescript/Javascript developer myself and also get tripped up with this sort of thing. It is unlikely that we are going to make changing to the actual packaging or build pipeline for now.
Does this issue still need to be looked at? I'm a first time open sourcer and would love to contribute! @xnuk
Go for it!
Minimal reproduction:
Note that this code is
.mjs
so it's ES Module. Runningnode bar.mjs
shows this error, probably typescript/babel/etc bundling issue: