octokit / plugin-throttling.js

Octokit plugin for GitHub’s recommended request throttling
MIT License
110 stars 35 forks source link

Import does not work #677

Closed raxod502 closed 8 months ago

raxod502 commented 8 months ago

When installing the latest version of the package in a new package.json with Node.js 20 LTS following the directions in the README:

% npm i @octokit/plugin-throttling

added 12 packages, and audited 13 packages in 937ms

found 0 vulnerabilities

% node
Welcome to Node.js v20.11.0.
Type ".help" for more information.
> require("@octokit/plugin-throttling")
Uncaught:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /home/raxod502/files/temp/example-repo/node_modules/@octokit/plugin-throttling/package.json
    at exportsNotFound (node:internal/modules/esm/resolve:303:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:593:13)
    at resolveExports (node:internal/modules/cjs/loader:591:36)
    at Module._findPath (node:internal/modules/cjs/loader:668:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1130:27)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

See also https://github.com/vercel/ncc/issues/1167.

gr2m commented 8 months ago

feels more like a bug with ncc than with the package? require("@octokit/plugin-throttling") doesn't work because it's an ESM module now, try import("@octokit/plugin-throttling")

wolfy1339 commented 8 months ago

Other users have experienced issues where tooling cannot find the module, and adding in a main field has helped them See https://github.com/octokit/core.js/pull/662

raxod502 commented 8 months ago

If require does not work, should the documentation (which says to use require) be updated?

image

raxod502 commented 8 months ago

feels more like a bug with ncc than with the package?

Note that ncc is not involved in the bug report here; I simply installed the package through NPM and tried to load it with require.

wolfy1339 commented 8 months ago

Yes, the docs need updating, but again, you should read the release notes as you seem to be upgrading this package

wolfy1339 commented 8 months ago

Fixed by #679

raxod502 commented 7 months ago

Thanks - I expect this will save people a lot of time with troubleshooting in future.