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

support for Next.js client side ? #57

Open
taylortm opened this issue Dec 15, 2022 · 0 comments
Open

support for Next.js client side ? #57

taylortm opened this issue Dec 15, 2022 · 0 comments

Comments

@taylortm
Copy link

so for whatever reason i cannot run m2s inside a next.js route.
"next": "^13.0.5",
"react": "^18.2.0",
"typescript": "latest",

when i run m2s from a command (schema.ts) with ts-node-dev with a tsconfig with module"commonjs" everything works fine.
"target": "es2017",
"module": "CommonJS",

but if i try to run the same code from inside a next.js .tsx file it crashes. i can get it to work if i do m2s(new Model()) instead of m2s(Model) but then it mangles certain things like Scehma.Types.ObjectIds.

my next.js tsconfig is set to:
"target": "es5",
"module": "esnext"

Is there any way to make m2s work in a .tsx file (NextJs "page")?
as a workaround for now i have a commands/ folder which has a schema.ts file which i run with ts-node-dev to create the schemas and write them to .json files.

i then load those .json files for use with react-jsonschema-form and swagger-jsdoc. this is really nice cuz i can build my schema definitions with m2s and load them into swagger-jsdoc and use @Swagger comments to markup my api routes.

the only downside is every time i change the model i have to re-run schema.ts instead of being able to build the schema dynamically for react-jsonschema-form. but being able to run m2s inside a tsx file would change that and make the framework more developer friendly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant