@libsql/client unable to be imported in a server action in Next.js 14
Answered
Short mackerel posted this in #help-forum
Short mackerelOP
I have upgraded to Next.js 14, and I'm unable to import
I'm using the Server Action to fetch data using SWR rather than a mutation, the action imports the following file which creates the DB client and Drizzle client:
This results in the following error:
I'm running using Bun, however the same error appears when using Node (through pnpm), and i've tried on canary aswell.
It worked in Next.js 13.
createClient
from @libsql/client
for use with Drizzle ORM.I'm using the Server Action to fetch data using SWR rather than a mutation, the action imports the following file which creates the DB client and Drizzle client:
import { drizzle } from "drizzle-orm/libsql";
import { createClient } from "@libsql/client";
import * as schema from "./schema";
const client = createClient({
url: process.env.DATABASE_URL!,
authToken: process.env.DATABASE_AUTH_TOKEN,
});
export const db = drizzle(client, { schema });
This results in the following error:
⨯ TypeError: (0 , _libsql_client__WEBPACK_IMPORTED_MODULE_0__.createClient) is not a function
at eval (./src/db/index.ts:11:76)
at (action-browser)/./src/db/index.ts (<project>/.next/server/app/(main)/(feed)/page.js:723:1)
at __webpack_require__ (<project>/.next/server/webpack-runtime.js:33:42)
at eval (actions.ts:8:61)
at (action-browser)/./src/app/(main)/(feed)/actions.ts (<project>/.next/server/app/(main)/(feed)/page.js:585:1)
at Function.__webpack_require__ (<project>/.next/server/webpack-runtime.js:33:42)
3 | import * as schema from "./schema";
4 |
> 5 | const client = createClient({
| ^
6 | url: process.env.DATABASE_URL!,
7 | authToken: process.env.DATABASE_AUTH_TOKEN,
8 | });
I'm running using Bun, however the same error appears when using Node (through pnpm), and i've tried on canary aswell.
It worked in Next.js 13.
Answered by Miniature Bull Terrier
@Short mackerel https://github.com/vercel/next.js/issues/57622
1 Reply
Miniature Bull Terrier
@Short mackerel https://github.com/vercel/next.js/issues/57622
Answer