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

When using pnpm and deploying Prisma Client to Heroku, it fails at runtime with Cannot find module '.prisma/client' #24199

Open
Jolg42 opened this issue May 15, 2024 · 2 comments
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: deployment/heroku topic: pnpm

Comments

@Jolg42
Copy link
Member

Jolg42 commented May 15, 2024

Bug description

Here is the error, from our platforms (heroku, library, ubuntu-20.04) test.
https://github.com/prisma/ecosystem-tests/actions/runs/9091632780/job/24986713804#step:8:4114

2024-05-15T07:36:15.186332+00:00 app[web.1]: > heroku@1.0.0 start
2024-05-15T07:36:15.186333+00:00 app[web.1]: > node index.js
2024-05-15T07:36:15.186333+00:00 app[web.1]: 
2024-05-15T07:36:15.297904+00:00 app[web.1]: Example app listening on port 45358!
2024-05-15T07:36:15.599760+00:00 heroku[web.1]: State changed from starting to up
2024-05-15T07:36:17.599044+00:00 app[web.1]: node:internal/modules/cjs/loader:1145
2024-05-15T07:36:17.599061+00:00 app[web.1]: const err = new Error(message);
2024-05-15T07:36:17.599065+00:00 app[web.1]: ^
2024-05-15T07:36:17.599065+00:00 app[web.1]: 
2024-05-15T07:36:17.599065+00:00 app[web.1]: Error: Cannot find module '.prisma/client'
2024-05-15T07:36:17.599066+00:00 app[web.1]: Require stack:
2024-05-15T07:36:17.599066+00:00 app[web.1]: - /app/index.js
2024-05-15T07:36:17.599072+00:00 app[web.1]: at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
2024-05-15T07:36:17.599073+00:00 app[web.1]: at Function.resolve (node:internal/modules/helpers:190:19)
2024-05-15T07:36:17.599078+00:00 app[web.1]: at /app/index.js:12:53
2024-05-15T07:36:17.599079+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/layer.js:95:5)
2024-05-15T07:36:17.599080+00:00 app[web.1]: at next (/app/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/route.js:149:13)
2024-05-15T07:36:17.599081+00:00 app[web.1]: at Route.dispatch (/app/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/route.js:119:3)
2024-05-15T07:36:17.599081+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/layer.js:95:5)
2024-05-15T07:36:17.599082+00:00 app[web.1]: at /app/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/index.js:284:15
2024-05-15T07:36:17.599082+00:00 app[web.1]: at Function.process_params (/app/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/index.js:346:12)
2024-05-15T07:36:17.599083+00:00 app[web.1]: at next (/app/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/index.js:280:10) {
2024-05-15T07:36:17.599083+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2024-05-15T07:36:17.599083+00:00 app[web.1]: requireStack: [ '/app/index.js' ]
2024-05-15T07:36:17.599083+00:00 app[web.1]: }
2024-05-15T07:36:17.599086+00:00 app[web.1]: 
2024-05-15T07:36:17.599090+00:00 app[web.1]: Node.js v20.13.1

How to reproduce

See https://github.com/prisma/ecosystem-tests/tree/dev/platforms/heroku

Expected behavior

It should work (it was working before)

Prisma information

Environment & setup

  • OS: Linux
  • Database: NA
  • Node.js version: 20.13.1

Prisma Version

5.15.0-dev.5 for example, but all versions should be affected as it's not a regression from Prisma's side but a change in the buildpack used by Heroku.

@Jolg42 Jolg42 added bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: pnpm topic: deployment/heroku labels May 15, 2024
@Jolg42
Copy link
Member Author

Jolg42 commented May 15, 2024

See internal Slack thread

One important thing to note, is that our current test has NPM_CONFIG_PRODUCTION=false & NODE_MODULES_CACHE=false set on Heroku as env vars.

After investigating, it looks like the Pruning devDependencies step of the heroku/nodejs buildpack changed, and is not skipped anymore.

A deployment using heroku/nodejs buildpack version 244, where runtime is working:

heroku buildpacks:set https://github.com/heroku/heroku-buildpack-nodejs.git#v244 -a name-of-app
....
remote: -----> Pruning devDependencies
remote:        Skipping because NPM_CONFIG_PRODUCTION is 'false'
remote:        

remote: -----> Compressing...
remote:        Done: 120.1M

A deployment using heroku/nodejs buildpack version 245, where runtime is failing with the Prisma Client error mentioned earlier:

heroku buildpacks:set https://github.com/heroku/heroku-buildpack-nodejs.git#v245 -a name-of-app

remote: -----> Pruning devDependencies
remote:        
remote:        devDependencies:
remote:        - @types/node 16.18.97
remote:        - heroku 8.11.5
remote:        - prisma 5.14.0-dev.74
remote:        - ts-node 10.9.2

remote: -----> Compressing...
remote:        Done: 89.7M

The changelog https://github.com/heroku/heroku-buildpack-nodejs/blob/HEAD/CHANGELOG.md
Shows that v245 added support for pnpm -> heroku/heroku-buildpack-nodejs#1224

Looking at https://github.com/heroku/heroku-buildpack-nodejs/blob/a409b633d7925c3002ba4568bc833093cbd75237/lib/dependencies.sh#L338
It looks like the behavior is not the same for pnpm as for yarn and npm and so this behavior is expected at the moment as the env vars are not used in that newer code path.

@Jolg42
Copy link
Member Author

Jolg42 commented May 15, 2024

Current workaround: using a custom out path works.
Example

generator client {
  provider = "prisma-client-js"
  output   = "../src/generated/client"
}

See https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/generating-prisma-client#using-a-custom-output-path

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. topic: deployment/heroku topic: pnpm
Projects
None yet
Development

No branches or pull requests

1 participant