prisma: Using Prisma with Rollup or Webpack in Node causes a runtime error
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/issues/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 https://github.com/netlify/create-react-app-lambda/issues/24
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 17 (10 by maintainers)
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 therequire
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.
Ugh, so the README at https://github.com/node-fetch/node-fetch lies to us 😕
This is the config that worked for me: https://github.com/prisma/prisma/issues/2303#issuecomment-768358529