zenstack icon indicating copy to clipboard operation
zenstack copied to clipboard

Zenstack VSCode plugin import from a NPM package leads to `Cannot find model file` error

Open Tsimopak opened this issue 1 year ago • 1 comments

Zenstack plugin import from a npm package leads to Cannot find model file (although it does work when trying to do npx zenstack generate) Plugin version: v2.3.0

An easy way to reproduce in case you need a npm package: npm install @dptickets2/common

then in schema.zmodel file:

import '@dptickets2/common/models/outbox'

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")}

The issue is quite annoying because right now in vscode, i have an error indication that reflects on my whole repository.

Tsimopak avatar Jul 31 '24 10:07 Tsimopak

Another issue - from some reason the assumption is that i must have in my npm module a schema.zmodel, specifically with schema name, even if it's not being used and u make also other zmodel fiels and include only them.

Tsimopak avatar Aug 01 '24 18:08 Tsimopak

Hi @Tsimopak , a late follow up here 😄. ZenStack uses standard node.js module resolution to resolve imported zmodel files (by calling require.resolve) , so the imported package need to have proper exports in package.json file.

Adding the following should resolve the error:

{
  "exports": {
    ... 
    "./models/outbox.zmodel": "./models/outbox.zmodel"
  }
}

Resolving the issue fornow.

ymc9 avatar Jan 06 '25 08:01 ymc9