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

Bundling fails on 2.21.0 #6564

Closed
prescience-data opened this issue Apr 13, 2021 · 24 comments · Fixed by #8842
Closed

Bundling fails on 2.21.0 #6564

prescience-data opened this issue Apr 13, 2021 · 24 comments · Fixed by #8842
Assignees
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. status/needs-fix-confirmation team/client Issue for team Client. topic: bundler topic: esbuild topic: _http_common topic: undici topic: webpack
Milestone

Comments

@prescience-data
Copy link

prescience-data commented Apr 13, 2021

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

  1. Install Prisma and ESBuild using PNPM.
  2. Run prisma generate
  3. Run esbuild app.js --bundle --platform=node --target=node14
  4. 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
@matthewmueller matthewmueller added team/client Issue for team Client. topic: esbuild labels Apr 14, 2021
@matthewmueller
Copy link
Contributor

Can you share an example script on how to reproduce this?

@larrybek
Copy link

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.

@matthewmueller
Copy link
Contributor

A repro we could clone and try out ourselves would be greatly appreciated!

@matthewmueller
Copy link
Contributor

Next steps:

  • Try upgrading undici and see if that fixes it.

@larrybek
Copy link

@matthewmueller is a private project but I can refer to the core issue, webpack tries to find a package in package.json but without result, as it's a native node.js module and it generates its own package.json where the version of "_http_common" is empty (as it didn't find a package there).
serverless-bundle on a build flow uses yarn install --non-interactive --frozen-lockfile and as the version is missing it crashes.
Ignoring helped just not add it to package.json with an empty string for a version. This way I solved the issue but it's a hack than a solution.

@matthewmueller matthewmueller added this to the 2.22.0 milestone Apr 14, 2021
@prescience-data
Copy link
Author

A repro we could clone and try out ourselves would be greatly appreciated!

Lol sorry, I left the <!-- in the original ticket, just removed it now.

  1. Install Prisma and ESBuild using PNPM.
  2. Run prisma generate
  3. Run esbuild app.js --bundle --platform=node --target=node14
  4. See error

@prescience-data
Copy link
Author

prescience-data commented Apr 15, 2021

@matthewmueller is a private project but I can refer to the core issue, webpack tries to find a package in package.json but without result, as it's a native node.js module and it generates its own package.json where the version of "_http_common" is empty (as it didn't find a package there).
serverless-bundle on a build flow uses yarn install --non-interactive --frozen-lockfile and as the version is missing it crashes.
Ignoring helped just not add it to package.json with an empty string for a version. This way I solved the issue but it's a hack than a solution.

I thought this had solved it for me as well, but one of the modules in my monorepo is actually instantiating a http node server, so it breaks now as the native Node http module has been excluded and there is no way to "reinclude" it in package.json.

@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. labels Apr 15, 2021
@JamesForan
Copy link

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.

@larrybek , I have the same issue. New to webpack though. can you advise how you ignore the package?

Thanks

James

@larrybek
Copy link

@JamesForan I have been using serverless-bundle which has initial functionality called forceExclude 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.

@millsp
Copy link
Member

millsp commented May 3, 2021

We are waiting for undici to release v4, in the meantime you could mark their internal dependency as external with --external:_http_common.

@trivigy
Copy link

trivigy commented May 23, 2021

@millsp Any recommendations of a workaround in the meantime that does not include simply cutting out the dependency?

@pantharshit00 pantharshit00 added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels May 23, 2021
@softmarshmallow
Copy link

softmarshmallow commented May 27, 2021

How should i be dealing with my webpack.config? (using serverless + prisma)

Module not found: Error: Can't resolve '_http_common' in '/server/node_modules/@prisma/client/runtime'

@pantharshit00
Copy link
Contributor

Hey @softmarshmallow

Use the following webpack config which this is being fixed:

module.exports = {
    webpack: (config, {isServer}) => {
        if (isServer) {
            config.externals.push('_http_common');        }
        return config;
    },
    target: 'serverless',
};

Above config is for next js but you can also transfer this to your custom config.

@mubaidr
Copy link

mubaidr commented May 28, 2021

^ target: 'serverless' is not supported. what webpack version are u using?

Error: Unknown target 'serverless'

@pantharshit00
Copy link
Contributor

@mubaidr It is for next js. Ignore it if you are not using next js.

@millsp
Copy link
Member

millsp commented May 28, 2021

In your webpack.config.js, add externals: ['_http_common', 'encoding'],

@millsp
Copy link
Member

millsp commented May 28, 2021

@trivigy no other workaround for now, sorry about that. What is your setup?

@trivigy
Copy link

trivigy commented May 29, 2021

@millsp I run prisma on electron. The suggest workaround seems to work. Thanks. I just upgraded to v2.23.0. If I encounter any more issues related to this specific problem I will follow up. Are those dependencies not used undici? Or are they used by undici but the functionality that prisma needs from undici does not invoke those dependencies? Just trying to understand the scope of possible issues to come. I am guessing by defining them external, they are not being bundled which may cause various problem down the line.

@pantharshit00
Copy link
Contributor

pantharshit00 commented May 30, 2021

_http_common is a private module built into node js itself(https://github.com/nodejs/node/blob/master/lib/_http_common.js), just like fs or util. It is not a publicly documented API. It was used by undici 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.

@matthewmueller
Copy link
Contributor

matthewmueller commented Jun 2, 2021

Workaround for today

  • Mark _http_common external in your bundler. It will still work as expected.
    • It's built into node node -e "console.log(require('_http_common'))"

Permanent Fix for Prisma

@doei
Copy link

doei commented Aug 15, 2021

With webpack 5, simply adding '_http_common' to an array in the externals build option wasn't enough for me, I had to specify it this way:

{
  // ...
  externals: {
    "_http_common": "commonjs2 _http_common",
  }
}

@ra-kesh
Copy link

ra-kesh commented Mar 20, 2022

With webpack 5, simply adding '_http_common' to an array in the externals build option wasn't enough for me, I had to specify it this way:

{
  // ...
  externals: {
    "_http_common": "commonjs2 _http_common",
  }
}

thank you...I was really struggling with this issue while using turbo repos with next js..but this resolved it..after adding it to the next.config.js

@millsp
Copy link
Member

millsp commented Mar 25, 2022

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)

@jamesbluecrow
Copy link

I can confirm that "@prisma/client": "^3.12.0-dev.28" works. Thanks @millsp !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. status/needs-fix-confirmation team/client Issue for team Client. topic: bundler topic: esbuild topic: _http_common topic: undici topic: webpack
Projects
None yet
Development

Successfully merging a pull request may close this issue.