prisma: TypeScript deploy "Cannot find module `.prisma/client`"

Bug description

When trying to deploy Prisma client to Elastic Beanstalk, I am seeing the following errors:

Error: Cannot find module '.prisma/client'
Require stack:
- /var/app/current/node_modules/@prisma/client/index.js
- /var/app/current/dist/utils/Prisma.js
- /var/app/current/dist/config/passport.js
- /var/app/current/dist/index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
at Function.Module._load (internal/modules/cjs/loader.js:690:27)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/var/app/current/node_modules/@prisma/client/index.js:1:16)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/var/app/current/node_modules/@prisma/client/index.js',
'/var/app/current/dist/utils/Prisma.js',
'/var/app/current/dist/config/passport.js',
'/var/app/current/dist/index.js'
]
}

How to reproduce

Follow along this prisma tutorial and attempt to deploy to AWS Elastic Beanstalk

Expected behavior

It to deploy properly.

Prisma information

Package.json :

...
"@prisma/cli": "2.15.0",
"@prisma/client": "2.15.0",
...

tsconfig.json

{
    "compilerOptions": {
      "lib": ["esnext"],
      "outDir": "dist",
      "moduleResolution": "node",
      "esModuleInterop": true,
      "experimentalDecorators": true,
      "emitDecoratorMetadata": true,
      "skipLibCheck": true,
      "forceConsistentCasingInFileNames": true,
    }
  }
  

I will say I have tried all different variations of tsconfig as well…

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 24 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Ok, after a bit more investigation, it turned out, that EB is not allowing any postinstall hook to write to the filesystem. There are 2 ways to fix this:

1. .npmrc

Create a .npmrc file with this content: unsafe-perm=true This let’s the postinstall hook write into the filesystem as is the case in a normal npm installation.

2. Add prestart hook

Unfortunately, EB doesn’t run the postinstall hook of the main application. However, you can add a prestart hook that runs prisma generate like so:

{
  "name": "eb-test",
  "scripts": {
    "start": "node ./bin/www",
    "prestart": "prisma generate"
  }
}

I suggest using the prestart hook to be on the safe side.

And @jimthedev did this start appearing in 2.15.0 or did you see this earlier already?

This is a brand new app so I don’t know but previous versions of Blitz apps worked using prisma so I suspect this is new.

Ok good to know! We’ll let you know here once it’s fixed.

I haven’t tried with 2.14.0 but I certainly can and report back.