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

"module" entry points to web bundle #45

Closed
KrysKruk opened this issue Oct 26, 2021 · 4 comments · Fixed by #159
Closed

"module" entry points to web bundle #45

KrysKruk opened this issue Oct 26, 2021 · 4 comments · Fixed by #159
Labels
Status: Blocked Some technical or requirement is blocking the issue Type: Bug Something isn't working as documented
Projects

Comments

@KrysKruk
Copy link

What happened?

I'm bundling my node.js code with webpack for serverless.
With bundled @octokit/webhooks-methods, my code doesn't run and throws an error: Exception: ReferenceError: crypto is not defined.

What did you expect to happen?

Code generated by webpack to run.

What the problem might be

@octokit/webhooks-methods defines these entries in package.json:

  "main": "dist-node/index.js",
  "module": "dist-web/index.js",
  "source": "dist-src/index.js",
  "types": "dist-types/index.d.ts",

Webpack favours module (see webpack/webpack#5756 ) because it helps with e.g. better tree shaking, but the module entry here points to the dist-web/index.js file which doesn't include crypto and buffer imports.

IMO the module entry should be renamed to browser.

@KrysKruk KrysKruk added the Type: Bug Something isn't working as documented label Oct 26, 2021
@ghost ghost added this to Bugs in JS Oct 26, 2021
@annrodriguez
Copy link

I am also running into this issue.

I just manually changed the module key in the package.json file to browser before packing up my serverless code as a test, and my code all worked as expected.

After changing browser back to the incorrect module see package.json standard and webpack docs...

I added a rule to the module key in my webpack configuration that specifies the correct mainField

{
  test: /node_modules\/@octokit\/webhooks(-methods)?/,
  resolve: {
    mainFields: ['main']
  }
}

I suspect if this bug is ever completed, this may have to change, but for now... this is working for me in case anyone else finds this thread.

@wolfy1339
Copy link
Member

Unfortunately this isn't a problem we can fix ourselves. This would be a problem with the build system, which is not maintained anymore.

This will get fixed once we switch to using pure ESM + seperate types

@wolfy1339 wolfy1339 added the Status: Blocked Some technical or requirement is blocking the issue label Jan 24, 2023
@wolfy1339
Copy link
Member

We are starting to migrate away from Pika, and towards using esbuild to generate the different bundles, and tsc to generate the types.

We will be able to get this addressed in a new major version

@wolfy1339
Copy link
Member

#159 Should help get this sorted out

In the meantime, you can always load the package from a CDN:

import { sign, verify } from "https://esm.sh/@octokit/[email protected]";

@wolfy1339 wolfy1339 linked a pull request Jun 4, 2023 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Blocked Some technical or requirement is blocking the issue Type: Bug Something isn't working as documented
Projects
No open projects
JS
  
Bugs
Development

Successfully merging a pull request may close this issue.

3 participants