Has Anyone Experienced an Error When Importing BskyAgent from @atproto/api?

This topic was automatically generated from Slack. You can find the original thread here.

Anyone made use of @atproto/api? When I **import** { BskyAgent } **from** '@atproto/api'; I get an error that it does not export BskyAgent

Appears to me that they exported their TS as CJS instead of ESM, despite what they documented. You can do something like:

import  Atproto from '@atproto/api'
const {BskyAgent} = Atproto
export default defineComponent({
  async run({ steps, $ }) {
    console.log(BskyAgent)
  },
})

weird - it worked as is in RunJS though?

your fix worked. any idea why it worked locally?

Locally I get the same error

weird :slightly_smiling_face: RunJS is an Electron based node/js type runner. I use it for quick tests

oh strange, I changed the directory I was in and was able to get it to work locally

let me check if this is a node 20 thing

cool beans - either way - thanks for the workaround

updating a workflow that did a bot posting to Mastodon to also do Bluesky

Actually fat fingered, this is what node 20 shows:

import {BskyAgent} from "@atproto/api"
        ^^^^^^^^^
SyntaxError: Named export 'BskyAgent' not found. The requested module '@atproto/api' 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 '@atproto/api';
const {BskyAgent} = pkg;

i wonder if these settings in RunJS ‘patched’ it over:

image.png

It’s worth reaching out upstream, they can easily bundle it to work for both.

nod. my bot is working :laughing:

As an FYI, I noticed something today. The docs specifically say Typescript (Get Started | Bluesky). I didn’t think that detail matter, but it appears it does. Once I wrapped the code with an async func, it actually worked just fine