ai icon indicating copy to clipboard operation
ai copied to clipboard

Module not found: Package path ./rsc is not exported from package

Open walter-grace opened this issue 4 months ago • 16 comments

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

image

Code example

No response

Additional context

No response

walter-grace avatar Mar 01 '24 23:03 walter-grace

added the folder source

walter-grace avatar Mar 01 '24 23:03 walter-grace

Can you share more about your system? Your operating system and node version (node -v) would be helpful.

MaxLeiter avatar Mar 01 '24 23:03 MaxLeiter

@MaxLeiter I'm having the same issue. pnpm, node v20.11.1

oayandosu avatar Mar 01 '24 23:03 oayandosu

Same version for me : v20.11.0

walter-grace avatar Mar 02 '24 00:03 walter-grace

Are you also on windows @oayandosu?

MaxLeiter avatar Mar 02 '24 00:03 MaxLeiter

@MaxLeiter Mac Sonoma. Turborepo as well. I had the same issue on Node 18 as well

oayandosu avatar Mar 02 '24 00:03 oayandosu

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?

briann avatar Mar 02 '24 03:03 briann

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

tmc avatar Mar 02 '24 05:03 tmc

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.

briann avatar Mar 02 '24 08:03 briann

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.

twxxk avatar Mar 02 '24 11:03 twxxk

Happening for me too with [email protected] node: v18.18.0

leo-paz avatar Mar 02 '24 17:03 leo-paz

Adding "moduleResolution": "bundler" to your tsconfig.json fix the problem.

image

Working for me now in Turborepo with Yarn.

IvanCoronado avatar Mar 03 '24 12:03 IvanCoronado

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.

joelhooks avatar Mar 03 '24 20:03 joelhooks

Getting this error when you switch moduleResolution from node to bundler CleanShot 2024-03-03 at 20 35 34@2x

This is on [email protected] and node v20.10.0

bdcorps avatar Mar 04 '24 01:03 bdcorps

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.

nckre avatar Mar 04 '24 10:03 nckre

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

holdenmatt avatar Mar 04 '24 18:03 holdenmatt