Next.js Discord

Discord Forum

Nextjs not being able to load a module.

Answered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
I am building a typescript library which I bundle using rollup and then later want to use in my nextjs project. I added the library into my package.json the folowing way:

"sdk-name": "../sdk-name",

The sdk project is located next to the nextjs project.

Vscode is totally fine with everything go to declaration works intellisense everything works. But when I try to use the sdk in a client component inside nextjs I get and error stating that the module could not be found when nextjs was compiling the page

Module not found: Can't resolve 'sdk-name'
2 | import { Button } from "@/components/ui/button";
3 | import { Card } from "@/components/ui/card";
> 4 | import { openPicker } from "sdk-name";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 |
6 | export default function Home() {
7 | function handleOpen() {
Answered by American black bear
I just tried switching to yarn and everything works as expected
View full answer

10 Replies

American black bearOP
The issue is even weirder than I thought, when I have the package installed via pnpm the behaviour is as described above but when I just take and copy paste the package into node modules it works just fine
American black bearOP
I know what the command does
pnpm correctly adds the simlink
but for some reason it doesn't work
American black bearOP
I just tried switching to yarn and everything works as expected
Answer
does it work outside the nextjs scope? say for example if you make a nodejs script and import/require the module, does it work?
oh well that means it's a bug then, worth to report in nextjs repo
American black bearOP
Look like some bug within pnpm