decs / typeschema

🛵 Universal adapter for TypeScript schema validation.
https://typeschema.com
MIT License
402 stars 13 forks source link

"Module not found" errors on next.js #24

Closed qcho closed 1 year ago

qcho commented 1 year ago

I had to downgrade to 0.11.0 because the library was asking me to install all the peer dependencies.

Tried with pnpm and npm. Same error.

./node_modules/.pnpm/@decs+typeschema@0.11.7_valibot@0.17.0/node_modules/@decs/typeschema/dist/deepkit-KEFZXADV.mjs:2:0
Module not found: Can't resolve '@deepkit/type'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/.pnpm/@decs+typeschema@0.11.7_valibot@0.17.0/node_modules/@decs/typeschema/dist/index.mjs
./src/server/routers/auth/login.ts
./src/server/routers/auth.ts
./src/server/index.ts
./src/app/api/trpc/[trpc]/route.ts

It seems there is an error where the _valibot variant is calling for the other deps.

decs commented 1 year ago

thanks for the flag! indeed I was able to repro when using typeschema on next.js. downgrading didn't work either, so I'll need to look into how next.js handles dynamic imports and optional peer dependencies. likely, we'll need a fix similar to how I've done on Vite a couple weeks ago: vitejs/vite#14489. I'll prioritize unblocking this

decs commented 1 year ago

found the root cause! it was due to webpack, the bundle used by Next.js. we're now using webpackIgnore on the external imports to mark them as external (8fa8b33) and I also added a check in our CI to avoid future regressions

the fix is out on v0.12.1. thanks a lot for reporting!

qcho commented 1 year ago

Great work! Thanks @decs ^_^