prisma: Bundling fails on 2.21.0
Bug description
After upgrading to 2.21.0
and running ESBuild to bundle, a new error occurs:
> ../../common/temp/node_modules/.pnpm/@prisma+client@2.21.0_prisma@2.21.0/node_modules/@prisma/client/runtime/index.js:24152:23:
error: Could not resolve "_http_common" (mark it as external to exclude it from the bundle)
24152 │ var common = require("_http_common");
and
"var runtimeRequire =
typeof __webpack_require__ === 'function' ?
__non_webpack_require__ : require // eslint-disable-line"
How to reproduce
- Install Prisma and ESBuild using PNPM.
- Run
prisma generate
- Run
esbuild app.js --bundle --platform=node --target=node14
- See error
Expected behavior
Prior to 2.21.0
bundling was successful.
Prisma information
// Datasources
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// Generators
generator client {
provider = "prisma-client-js"
binaryTargets = ["debian-openssl-1.1.x", "linux-musl", "windows", "darwin"]
}
ESBuild config
module.exports = {
bundle: true,
minify: false,
format: "cjs",
keepNames: true,
sourcemap: true,
platform: "node",
logLevel: "error",
target: ["node14"],
external: ["fsevents"],
outfile: "dist/run.js",
entryPoints: ["src/index.ts"],
metafile: false,
loader: { ".prisma": "file" },
}
Environment & setup
- OS: Windows
- Database: Postgres
- Node.js version: v14.16.0
- Prisma version: v2.21.0
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 19
- Comments: 24 (11 by maintainers)
Commits related to this issue
- build: fix build issue with prisma and _http_common https://github.com/prisma/prisma/issues/6564 — committed to zp-bots-telegram/group-tag-bot by zackpollard 2 years ago
- build: fix build issue with prisma and _http_common https://github.com/prisma/prisma/issues/6564 — committed to zp-bots-telegram/group-tag-bot by zackpollard 2 years ago
- build: fix build issue with prisma and _http_common https://github.com/prisma/prisma/issues/6564 — committed to zp-bots-telegram/group-tag-bot by zackpollard 2 years ago
- build: fix build issue with prisma and _http_common https://github.com/prisma/prisma/issues/6564 — committed to zp-bots-telegram/group-tag-bot by zackpollard 2 years ago
With webpack 5, simply adding
'_http_common'
to an array in theexternals
build option wasn’t enough for me, I had to specify it this way:In your
webpack.config.js
, addexternals: ['_http_common', 'encoding'],
I can confirm that
"@prisma/client": "^3.12.0-dev.28"
works. Thanks @millsp !I have a similar issue with @m-abdelwahab Im using
serverless-bundle
which uses webpack it was trying to find a module to bundle I needed to ignore the package_http_common
for bundling so it work.@millsp Any recommendations of a workaround in the meantime that does not include simply cutting out the dependency?
_http_common
is a private module built into node js itself(https://github.com/nodejs/node/blob/master/lib/_http_common.js), just likefs
orutil
. It is not a publicly documented API. It was used byundici
to improve http parsing performance but looks like they no longer need it in the latest release candidate version.undici
is maintained by Node JS folks so they know about this undocumented private module pretty well. So that is why you don’t need to bundle it as it is built into the runtime.Hey everyone, this has been fixed in
@prisma/client@dev
if you want to give it a try. Please let us know if you find anything unexpected. Thanks.(cc @prescience-data @ra-kesh @trivigy)
@mubaidr It is for next js. Ignore it if you are not using next js.
We are waiting for
undici
to releasev4
, in the meantime you could mark their internal dependency as external with--external:_http_common
.Hey @softmarshmallow
Use the following webpack config which this is being fixed:
Above config is for next js but you can also transfer this to your custom config.
@JamesForan I have been using
serverless-bundle
which has initial functionality calledforceExclude
but I know that its underneath is using webpack so there’s an option that this parameter is somehow passed to webpack. You can have a look on it, and it may give you some idea.