zenstack
zenstack copied to clipboard
Unable to Import Model from NPM Module in ZenStack
Hi,
I'm encountering an issue when trying to import a model from an NPM package into my ZenStack project. The import works fine when using a relative path, but fails when using an NPM module. The error message explicitly states:
Cannot find model file {CORRECT PATH}
Steps to Reproduce:
- I created a ZenStack project with workspaces and added a package containing a
.zmodelfile. - Attempted to import the model in my ZenStack schema:
import "my-npm-package/schema.zmodel"; // Fails - Ran the ZenStack CLI:
npx zenstack generate
Expected Behavior:
ZenStack should correctly resolve and use the imported model from the NPM module.
Actual Behavior:
- When using a relative path (
import "../../node_modules/my-npm-package/schema.zmodel";), the import works as expected. - When using the package (
import "my-npm-package/schema.zmodel";), ZenStack throws the following error:
(whereCannot find model file {CORRECT PATH}{CORRECT PATH}is the actual, valid path where the model exists insidenode_modules).
Environment:
- ZenStack Version: 2.11.6
- Node.js Version: 20.11.0
- NPM Version: 10.2.4
- OS: Windows
- Database : Postgresql
Reproducible Example:
To make it easier to debug, I’ve created a minimal reproducible example on StackBlitz:
👉 https://stackblitz.com/edit/stackblitz-starters-vtmmfxt3?file=package.json
Additional Context:
- The package is correctly installed in
node_modulesthrough workspaces. - Other parts of my application can correctly import it.
- The issue seems to be related to how ZenStack resolves module paths.
Any guidance or workaround would be greatly appreciated! Thanks in advance for your help.