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

Jest: cannot find module 'ai/rsc' #1649

Open
mrasoahaingo opened this issue May 19, 2024 · 2 comments
Open

Jest: cannot find module 'ai/rsc' #1649

mrasoahaingo opened this issue May 19, 2024 · 2 comments
Labels

Comments

@mrasoahaingo
Copy link

mrasoahaingo commented May 19, 2024

Description

I tried to implement test using the generated app with

npx create-next-app@latest --example with-jest with-jest-app

Then I use the example here https://sdk.vercel.ai/docs/getting-started/nextjs-app-router

But when I launch

yarn test

I have this error

yarn test
 FAIL  app/page.test.tsx
  ● Test suite failed to run

    Cannot find module 'ai/rsc' from 'app/page.tsx'

    Require stack:
      app/page.tsx
      app/page.test.tsx

      12 |   return (
      13 |     <div className="flex flex-col w-full max-w-md py-24 mx-auto stretch">
    > 14 |       {data && <pre>{JSON.stringify(data, null, 2)}</pre>}
         |              ^
      15 |       {messages.map((m, i) => (
      16 |         <div key={i} className="whitespace-pre-wrap">
      17 |           {m.role === 'user' ? 'User: ' : 'AI: '}

      at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:427:11)
      at Object.<anonymous> (app/page.tsx:14:14)
      at Object.<anonymous> (app/page.test.tsx:9:54)

(node:3728) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.473 s
Ran all test suites related to changed files.

Watch Usage
 › Press a to run all tests.
 › Press f to run only failed tests.
 › Press p to filter by a filename regex pattern.
 › Press t to filter by a test name regex pattern.
 › Press q to quit watch mode.
 › Press Enter to trigger a test run.

✨  Done in 191.55s.

Thank you for your help

Code example

No response

Additional context

No response

Note: It works with the Vitest version

@lewistham9x
Copy link

Getting the same issue here on plasmo

🔴 ERROR  | Build failed. To debug, run plasmo dev --verbose.
🔴 ERROR  | Failed to resolve 'ai/rsc' from './src/actions.tsx'
🔴 ERROR  | Cannot load file './rsc' from module 'ai'

Running plasmo@0.86.3, and tried ai version 3.0.0 to 3.0.2

@dnehring
Copy link

dnehring commented Jun 5, 2024

I was able to work-around the module resolution via jest config update in moduleNameMapper:

moduleNameMapper: { ... '^ai/rsc$': '<rootDir>/node_modules/ai/rsc/dist', }

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

No branches or pull requests

4 participants