tursodatabase / libsql-client-ts

TypeScript/JavaScript client API for libSQL
https://docs.turso.tech/sdk/ts/quickstart
MIT License
226 stars 32 forks source link

Module parse failed: Unexpected token #127

Open nibor98 opened 11 months ago

nibor98 commented 11 months ago

I have tried to use @libsql/client together with drizzle inside some new projects of mine, however I always get the following error, whatever I try.

Module parse failed: Unexpected token (1:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> MIT License
| 
| Copyright (c) 2023 libSQL

Import trace for requested module:
./node_modules/@libsql/client/LICENSE.md
./node_modules/@libsql/ ./node_modules/@libsql/ sync ^\.\/.*$
./node_modules/libsql/index.js
./node_modules/@libsql/client/lib-esm/sqlite3.js
./node_modules/@libsql/client/lib-esm/node.js

At first I though the problem was using bun, but this also happens every time with npm and pnpm.

Rest of my project setup:

Usage of @libsql/client:

import { createClient } from "@libsql/client";
import { drizzle } from "drizzle-orm/libsql";

const connection = createClient({
  url: process.env.DATABASE_URL || "",
  authToken: process.env.DATABASE_AUTH_TOKEN,
});

Thank you!

zeekrey commented 10 months ago

It seems like I encountered the same error message because I accidentally called libsql from a client component. It might be helpful to double-check that. Additionally, this error message was observed when using Next.js version < 13.5.5. In such cases, you need to modify the Next.js config. You can find more information on how to do this here: https://github.com/libsql/libsql-client-ts#using-the-library-with-nextjs .