Skip to content
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

Named export 'OAuth' not found #2240

Open
humbird0 opened this issue Nov 29, 2024 · 3 comments
Open

Named export 'OAuth' not found #2240

humbird0 opened this issue Nov 29, 2024 · 3 comments

Comments

@humbird0
Copy link

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?

@h3poteto
Copy link
Owner

h3poteto commented Dec 1, 2024

It seems like commonjs and esm problems. Do you have package.json?

@humbird0
Copy link
Author

humbird0 commented Dec 2, 2024

Yes. package.json looks like this:

{
  "name": "to_mastodon",
  "version": "1.0.0",
  "description": "Post things to mastodon",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "humbird0",
  "license": "CC0-1.0",
  "dependencies": {
    "express": "^4.21.1",
    "mastodon": "^1.2.2",
    "mastodon-api": "^1.3.0",
    "open": "^8.4.0"
  }
}

Incidentally, inside the package-lock.json file. mastodon-api lists oauth as a dependency.

"node_modules/mastodon-api": {
      "version": "1.3.0",
      "resolved": "https://registry.npmjs.org/mastodon-api/-/mastodon-api-1.3.0.tgz",
      "integrity": "sha512-h1S0f3HzPtaNTaIBXu/3PVsXhKgZGk9DYrqp+bNZwp1wjYhJnEKggossj+DCCQ72+2y3Kcd7fNP2cEkp9jK6Ig==",
      "license": "MIT",
      "dependencies": {
        "gulp-eslint": "^3.0.1",
        "mime": "^1.3.4",
        "oauth": "^0.9.15",
        "readline": "^1.3.0",
        "request": "^2.81.0"
      }
    },

@h3poteto
Copy link
Owner

h3poteto commented Dec 3, 2024

Are you using mastodon-api?
This package.json looks like you don't use megalodon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants