ai
ai copied to clipboard
Module not found: Package path ./rsc is not exported from package
Description
From examples/next-ai-rsc
When downloading the code from Github repo and running pnpm install + pnpm dev. And run into an module error: Failed to compile ./components/llm-stocks/stock-purchase.tsx:4:0 Module not found: Package path ./rsc is not exported from package C:\Users\nicoz\Downloads\ai-main\ai-main\node_modules.pnpm\node_modules\ai (see exports field in C:\Users\nicoz\Downloads\ai-main\ai-main\node_modules.pnpm\node_modules\ai\package.json) 2 | 3 | import { useId, useState } from 'react';
4 | import { useActions, useAIState, useUIState } from 'ai/rsc'; 5 | import { formatNumber } from '@/lib/utils'; 6 | 7 | import type { AI } from '../../app/action';
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module: ./components/llm-stocks/index.tsx
Code example
No response
Additional context
No response
added the folder source
Can you share more about your system? Your operating system and node version (node -v
) would be helpful.
@MaxLeiter I'm having the same issue. pnpm, node v20.11.1
Same version for me : v20.11.0
Are you also on windows @oayandosu?
@MaxLeiter Mac Sonoma. Turborepo as well. I had the same issue on Node 18 as well
Hitting this issue on linux, yarn, node 21.6.2. Here's the build failure I encounter:
Type error: Cannot find module 'ai/rsc' or its corresponding type declarations.
> 1 | import { createAI } from 'ai/rsc';
If I run the following from my project root:
cp node_modules/ai/rsc/dist/rsc-types.d.ts node_modules/ai/rsc/dist/index.d.ts
Then the build completes fine. I see that we're specifying rsc-types.d.ts
as the types
value in ai/package.json
's exports block for ./rsc
, but perhaps some build tooling here doesn't respect this and is looking for index.d.ts
?
Running pnpm install [email protected]
resolves this for me:
dependencies:
- ai 3.0.2
+ ai 3.0.1 (3.0.2 is available)
When I install 3.0.2:
dependencies:
- ai 3.0.1
+ ai 3.0.2 <- ../../packages/core
I'm still able to repro on both [email protected]
and [email protected]
.
I pushed up a branch (https://github.com/vercel/ai/pull/1043) which changes rsc-types.ts
to index.ts
and I'm able to use it locally to successfully import ai/rsc
. It's a naive solution and I'm not sure if it's the right one, but putting it out there in case it helps.
Same. When I copy next-ai-rsc to a different directory and run pnpm install ai@latest (3.0.2) and then pnpm dev, it works.
Happening for me too with [email protected]
node: v18.18.0
Adding "moduleResolution": "bundler"
to your tsconfig.json
fix the problem.
Working for me now in Turborepo with Yarn.
Same issue with node v20.5.0
pnpm 8.7.0
in a turborepo
here's the repo https://github.com/badass-courses/course-builder
adding the above moduleResolution: bundler
resolved the issue.
Getting this error when you switch moduleResolution
from node
to bundler
This is on [email protected]
and node v20.10.0
Had some issues in my own project which was based on the vercel chatbot. In addition to changing moduleResolution
to bundler
, had to remove --turbo
flag from dev
build to make it work.
Hit the same issue on a fresh git clone of this repo. Node v20.9.0, pnpm 8.12.0, macOS 12.3.1
For now, pnpm install [email protected]
fixed it for me