question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
f0rr0commented, 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.

1reaction
janpiocommented, Jun 7, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

0 - Stack Overflow
After some google research, i figured out how to fix this bug: install custom-webpack ( npm install @angular-builders/custom-webpack ...
Read more >
Turbopack, the successor to Webpack - Hacker News
The project is just a small server rendered web app (using Crystal) that I wanted to add papercss, trix, hotwire/stimulus and hotwire/turbo to...
Read more >
TypeScript: Cannot use import statement outside a module
Another common cause of the "Cannot use import statement outside a module" error in TypeScript is trying to run a TypeScript file directly...
Read more >
How To Solve Module Not Found Can't Resolve 'fs' in Next.js
When we use Next.js, we have a Webpack setup out of the box to bundle our app. In essence, Next.js is a web...
Read more >
next js unexpected token export - You.com | The AI Search ...
Please note you should use Node.js even versions for production. ... /benjamin/Developer/tests/prisma-adapter/.next/server/webpack-api-runtime.js (33:42) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found