(v6) Missing dependencies @valibot/to-json-schema and effect
Description
After upgrading to v6 beta, I get these errors when running the app:
WARNING in ./node_modules/@ai-sdk/provider-utils/dist/index.mjs
⚠ Module not found: Can't resolve 'effect' in '/app/node_modules/@ai-sdk/provider-utils/dist'
╭─[516:33]
514 │ var effectToJsonSchema = (schema) => async () => {
515 │ try {
516 │ const { JSONSchema } = await import("effect");
· ────────────────
517 │ return JSONSchema.make(schema);
518 │ } catch (e) {
╰────
WARNING in ./node_modules/@ai-sdk/provider-utils/dist/index.mjs
⚠ Module not found: Can't resolve '@valibot/to-json-schema' in '/app/node_modules/@ai-sdk/provider-utils/dist'
╭─[527:37]
525 │ return async () => {
526 │ try {
527 │ const { toJsonSchema } = await import("@valibot/to-json-schema");
· ─────────────────────────────────
528 │ return toJsonSchema(schema);
529 │ } catch (e) {
╰────
AI SDK Version
- ai: 6.0.0-beta.95
- @ai-sdk/react: 3.0.0-beta.95
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
I dug up and found more info:
This is happening only as a warning, and due to the fact that these two packages are optional peer dependencies. See https://github.com/vercel/ai/blob/35e445d20d39d2780a7e61803514abc76bded2cb/packages/provider-utils/package.json#L64-L74
I assume this is temporary, and that this code will eventually swallow the warning and not show it. It may be related to the fact that this is a beta version of the ai-sdk packages. The code that throws these exceptions even has a TODO note:
See https://github.com/vercel/ai/blob/35e445d20d39d2780a7e61803514abc76bded2cb/packages/provider-utils/src/to-json-schema/valibot-to-json-schema.ts#L9
But it is a bit bothering to have these warnings when everything works ok.
We support the different validation modules since https://github.com/vercel/ai/pull/9381. If you want to use them, you have to install them yourself as app dependency. You shouldn't get the warning/error unless you actually use the code though, your setup seems to be doing some kind of static analysis?
We think there is a better way that does not require the optional dependencies, but we couldn't prioritize the work on it yet
You shouldn't get the warning/error unless you actually use the code though,
We're not using this, the code is not running.
your setup seems to be doing some kind of static analysis?
Yes, that's it. I'll see if it's something we can check up on our side as well.
I'm getting this after installing vanilla create-next-app /examples/next-openai-pages example
○ Compiling /basics/stream-text ...
⚠ ./node_modules/.pnpm/@[email protected][email protected]/node_modules/@ai-sdk/provider-utils/dist/index.mjs
Module not found: Can't resolve 'effect' in '/home/jase/repos/scratchpad/nextjs/next-openai-app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@ai-sdk/provider-utils/dist'
Import trace for requested module:
./node_modules/.pnpm/@[email protected][email protected]/node_modules/@ai-sdk/provider-utils/dist/index.mjs
./node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@ai-sdk/react/dist/index.mjs
I'm also hitting this in a Next.js app (inside an NX monorepo):
> nx run dashboard:build:production
▲ Next.js 14.2.0
- Environments: .env.local, .env
- Experiments (use with caution):
· esmExternals
· instrumentationHook
Creating an optimized production build ...
Failed to compile.
../../node_modules/@ai-sdk/provider-utils/dist/index.mjs:520:26
Module not found: Can't resolve 'effect'
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
../../node_modules/ai/dist/index.mjs
[redacted]
../../node_modules/@ai-sdk/provider-utils/dist/index.mjs:531:30
Module not found: Can't resolve '@valibot/to-json-schema'
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
../../node_modules/ai/dist/index.mjs
[redacted]
> Build failed because of webpack errors
I'm also not using those libraries and everything was fine in v5. And these are not warnings, the build is actually failing.
UPDATE: in case anyone else runs into this, I was able to work around it by adding this to my next.config.js
const nextConfig = {
// other stuff
webpack: (config) => {
// other stuff
config.resolve.alias = {
...config.resolve.alias,
'effect': false,
'@valibot/to-json-schema': false,
};
return config;
},
}
module.exports = nextConfig;