Next.js Discord

Discord Forum

Error when importing library

Unanswered
English Lop posted this in #help-forum
Open in Discord
English LopOP
"TypeError: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of URL" ?? I don't understand. Why is it erroring when it's receiving URL when it expects URL?

23 Replies

English LopOP
Is this some client-server thing I'm not getting
sorry wrong one
can you add code or something
@Anay-208 | Ping in replies can you add code or something
English LopOP
Well this is the file
import { z } from "zod";
import nspell from 'nspell'
import dictionary from 'dictionary-en'
import {
    createTRPCRouter,
    publicProcedure,
} from "~/server/api/trpc";

const spellcheck = nspell(Buffer.from(dictionary.aff), Buffer.from(dictionary.dic))

export const wordRouter = createTRPCRouter({
    isWord: publicProcedure
        .input(z.object({ word: z.string() }))
        .query(({ input }) => {
            return spellcheck.correct(input.word);
        }),
});
It errors on the import of dictionary
But the thing is on a different page where it's being imported that doesn't happen
@Anay-208 | Ping in replies hmm, its likely a issue with the package compatibility with the latest version
English LopOP
the issue is that an import from another page works fine
but from my main page no
Are you importing the file which imports this specific package in the middleware?
@Anay-208 | Ping in replies Oh, are you using middleware?
English LopOP
No
But I'm using that trpc route in 2 different files
and in only one it works
are any of your routes edge runtime
English LopOP
No
The difference between them is one is server component and one is client
when I used .useQuery() for it on the client it worked fine
when i just fetched it on the server i get an error
Are yous ure you get the error in import, or do you get it with nspell or something?
@Anay-208 | Ping in replies Are yous ure you get the error in import, or do you get it with nspell or something?
English LopOP
I'm not sure but it only works when using server trpc
Once I just switched the file to client trpc it works