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

Postinstall script fails with PNPM workspaces due to npm ERR! Cannot read properties of null (reading 'matches') #14944

Closed
ErlanBelekov opened this issue Aug 23, 2022 · 11 comments · Fixed by #18646
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: pnpm workspaces topic: pnpm
Milestone

Comments

@ErlanBelekov
Copy link

ErlanBelekov commented Aug 23, 2022

Bug description

When running pnpm install in a monorepo, with this structure

packages
    server
         prisma
               schema.prisma
    shared-utils
         package.json
    web
         package.json
pnpm-workspace.yaml
package.json

I get this error:

#0 2.239
#0 2.239 > @hub/shared-utils@1.0.0 generate /app/packages/shared-utils
#0 2.239 > pnpm prisma generate
#0 2.239
#0 36.80 Prisma schema loaded from ../server/prisma/schema.prisma
#0 451.1 npm ERR! Cannot read properties of null (reading 'matches')
#0 451.2
#0 451.2 npm ERR! A complete log of this run can be found in:
#0 451.2 npm ERR!     /root/.npm/_logs/2022-08-23T02_34_57_814Z-debug-0.log
#0 451.2 Error: Command failed with exit code 1: npm install -D prisma@3.15.2
#0 451.3 undefined
#0 451.3 /app/packages/shared-utils:
#0 451.3  ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  @hub/shared-utils@1.0.0 generate: `pnpm prisma generate`
#0 451.3 Exit status 1

my package shared-utils installs prisma, web depends on shared-utils

shared-utils has a custom postinstall script, which generates Prisma client from custom location(from server package).
This is package.json of shared-utils

{
  "name": "@example/shared-utils",
  "version": "1.0.0",
  "main": "dist/src/index.js",
  "types": "dist/src/index.d.ts",
  "private": true,
  "license": "MIT",
  "scripts": {
    "build": "rm -rf dist && tsc --build",
    "test": "jest",
    "precommit": "eslint --ext .ts \"*/**/*\" --fix && prettier --write .",
    "postinstall": "pnpm prisma generate"
  },
  "dependencies": {
    "currency.js": "^2.0.4",
    "@prisma/client": "3.15.2",
    "date-fns": "^2.28.0"
  },
  "devDependencies": {
    "@example/eslint-config": "1.0.0",
    "@example/prettier-config": "1.0.0",
    "prisma": "3.15.2"
  },
  "prisma": {
    "schema": "../server/prisma/schema.prisma"
  },
  "prettier": "@example/prettier-config",
  "jest": {
    "preset": "ts-jest",
    "roots": [
      "src"
    ],
    "modulePaths": [
      "src"
    ],
    "moduleDirectories": [
      "node_modules"
    ]
  }
}

How to reproduce

  1. Go to project root.
  2. Run pnpm install
  3. See error

Expected behavior

pnpm install installs packages, and Prisma schema is generated automatically

Prisma information

Environment & setup

  • OS: Mac OS,
  • Database: PostgreSQL
  • Node.js version: 16.13.1

Prisma Version

3.15.2
@ErlanBelekov ErlanBelekov added the kind/bug A reported bug. label Aug 23, 2022
@ErlanBelekov
Copy link
Author

ErlanBelekov commented Aug 23, 2022

works now magically

Edit: it doesn't, the issue is still here

@ErlanBelekov ErlanBelekov reopened this Aug 23, 2022
@do4gr do4gr added team/client Issue for team Client. topic: pnpm bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels Aug 23, 2022
@janpio
Copy link
Member

janpio commented Aug 23, 2022

Can you maybe create a new project, and generate the minimal setup that is required to reproduce this and put it on GitHub? That would be best for us to reproduce - and then potentially fix the issue. Thanks.

@ErlanBelekov
Copy link
Author

sure @janpio , I'll try to do this in next few days approx.

@whexy
Copy link

whexy commented Aug 24, 2022

Same problem here.
A temporary workaround is to use pnpm add @prisma/client after prisma generate.

@ErlanBelekov
Copy link
Author

@whexy could you show the full code for workaround please?

@ErlanBelekov
Copy link
Author

@janpio when will Prisma support PNPM? 👀

seems like this is related to these issues, but I still haven't managed to make it work
#9848
#12501

@ErlanBelekov
Copy link
Author

adding public-hoist-pattern[]=*prisma* to .npmrc file fixed this issue, took the solution from here

#12921

@timmeade
Copy link

Same problem here. A temporary workaround is to use pnpm add @prisma/client after `prisma generateor

This worked for me

@heyfirst
Copy link

Same problem here. A temporary workaround is to use pnpm add @prisma/client after `prisma generateor

This worked for me too

@millsp
Copy link
Member

millsp commented Apr 14, 2023

Hey folks, we have just improved our pnpm detection logic to fix this issue, and we will release this in our 4.13.0 release. That said, you can try it now by installing our dev version. npm install prisma@dev. Feedback welcome!

@jlemrond
Copy link

@millsp Some feedback for you. Installed prisma@dev with pnpm, fixed the issue and worked like a charm. Thanks.

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. team/client Issue for team Client. topic: pnpm workspaces topic: pnpm
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants