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

Using Prisma with Rollup or Webpack in Node causes a runtime error #5250

Closed
f0rr0 opened this issue Jan 23, 2021 · 17 comments
Closed

Using Prisma with Rollup or Webpack in Node causes a runtime error #5250

f0rr0 opened this issue Jan 23, 2021 · 17 comments
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: dependencies topic: serverless topic: webpack

Comments

@f0rr0
Copy link

f0rr0 commented Jan 23, 2021

Bug description

I have traced this to node-fetch v 2.x which is a dependency of the fetch engine.

https://github.com/node-fetch/node-fetch/blob/b5e2e41b2b50bf2997720d6125accaf0dd68c0ab/src/body.js#L14

node-fetch/node-fetch#412

encoding seems to be a peer dependency for node-fetch. A bundler like webpack or rollup will include the require and crash at runtime since encoding is not installed.

Either prisma should upgrade the node-fetch dependency to v3 which does away with this or include a cautionary note in the README like node-fetch did : https://github.com/node-fetch/node-fetch/blob/2.x/README.md#bodytextconverted

Other repos depending on node-fetch 2.x also faced a similar issue netlify/create-react-app-lambda#24

@pantharshit00 pantharshit00 added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. tech/typescript Issue for tech TypeScript. topic: dependencies team/client Issue for team Client. labels Jan 27, 2021
@pantharshit00
Copy link
Contributor

Can you share a simple reproduction? Then we can confirm this and maybe replace node-fetch with something else as it is not a very core dependency.

We have some e2e tests for bundlers which havent failed so maybe you can look them as an example: https://github.com/prisma/e2e-tests/tree/dev/bundlers

@f0rr0
Copy link
Author

f0rr0 commented Jan 27, 2021 via email

@f0rr0
Copy link
Author

f0rr0 commented Jan 27, 2021

Here is the reproduction
prisma/ecosystem-tests#1314

@pantharshit00
Copy link
Contributor

THanks for that. Marking this as confirmed. We can try eliminating this dep.

@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Feb 3, 2021
@millsp millsp self-assigned this Apr 15, 2021
@matthewmueller
Copy link
Contributor

matthewmueller commented Jun 2, 2021

You're try bundling node_modules all together in one output JS file, you get a runtime error trying to run that output JS file. PR for context.

Am I understanding this correctly?

If so, a couple questions:

  • What's your use case? Perhaps something to do with Lambda?
  • What is the runtime error that you're seeing @f0rr0?

@f0rr0
Copy link
Author

f0rr0 commented Jun 2, 2021

Use case is generating a single asset that I can distribute to serverless environments. without the need to manage things like lambda layers. Also the generated asset is run through a minifier to reduce size and gain marginal improvement in startup perf.

The error is basically that a dependency of prisma has an implicit dependency on a module called encoding. This dependency is not installed when installing prisma. Neither is it mentioned in the prisma readme. Under normal circumstances the code path never reaches the require for that dependency but when bundled it does causing an error.

Ideally considering the reach and popularity of this project, it will be better to not have such implicit dependencies or make assumptions about the modules available at runtime. I suggest to either add a note in the docs or better yet replace this dependency with a more sensible choice.

@dvins
Copy link

dvins commented Jun 2, 2021

Closely related to this is the ESM support. See #5030 and #4920.

@f0rr0
Copy link
Author

f0rr0 commented Jun 4, 2021

Tbh I don't fully understand why/how the crash happens and it's been a while since I encountered it. I was able to resolve it by making modifications to the bundler config.

A guess is that perhaps the bundler hoists the require calls.

@f0rr0
Copy link
Author

f0rr0 commented Jun 4, 2021

This is the config that worked for me: #2303 (comment)

@janpio
Copy link
Member

janpio commented Jun 4, 2021

Why isn't renovate suggesting an update to node-fetch@3 here anyway @Jolg42?

@Jolg42
Copy link
Member

Jolg42 commented Jun 7, 2021

Because v3 in not on latest but on next.
https://www.npmjs.com/package/node-fetch
Screen Shot 2021-06-07 at 10 02 09

I re-configured Renovate, it should open a PR soon 3c00990

@janpio
Copy link
Member

janpio commented Jun 7, 2021

Ugh, so the README at https://github.com/node-fetch/node-fetch lies to us :/

@Jolg42
Copy link
Member

Jolg42 commented Jun 8, 2021

Indeed... README is incorrect Current stable release (3.x) should be 2.x here
I found the v3 roadmap issue here node-fetch/node-fetch#668

Created an issue node-fetch/node-fetch#1184

@mbalc
Copy link

mbalc commented Sep 8, 2021

what can I do to circumvent this issue?

@millsp
Copy link
Member

millsp commented Sep 8, 2021

You can mark this dependency as external for now.

@matthewmueller
Copy link
Contributor

It seems like the current workaround is to mark the dependency as external.

The longer-term fix is to upgrade to node-fetch 3.x, which is currently blocked by #7618.

@millsp
Copy link
Member

millsp commented Jun 8, 2022

Closing this as this is not an issue anymore
prisma/ecosystem-tests#2857

@millsp millsp closed this as completed Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: dependencies topic: serverless topic: webpack
Projects
None yet
Development

No branches or pull requests

8 participants