Skip to content

Named export 'OAuth' not found #2240

@humbird0

Description

@humbird0

I tried to run the example for generating and Authorization URL, but Node JS failed with this error.

import generator, { OAuth } from 'megalodon'
                    ^^^^^
SyntaxError: Named export 'OAuth' not found. The requested module 'megalodon' 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 'megalodon';
const { OAuth } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:177:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:260:5)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:543:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5)

Node.js v22.11.0

What I did:

  1. I installed the latest version of Node JS in Windows 10, using its MSI installer.
  2. In a folder on my hard drive, I opened a command prompt and typed: npm install megalodon
  3. I logged into a mastodon instance and used Firefox's dev tools to find the clientid and the clientsecret from the "Storage" tab and "Indexed DB" section.
  4. I created a file called "register_application.js" and pasted the 1st example code under the "Authorization" section of your readme.
  5. I modified the BASE_URL, clientId, and clientSecret with the values from the web dev tools. (actual values redacted for privacy)
    const BASE_URL = 'https://mymastodon.website'
    let clientId = "xxxxxxxxxx"
    let clientSecret = "yyyyyyyyy"
  6. I created a CMD file containing:
node register_application.js
pause
  1. When I ran this CMD file, the error occurred.

Which part did I do wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions