tursodatabase / tursodatabase/libsql-client-ts

@libsql/client prints several module warnings in Next.js

Open
#74 12 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
576
Forks
69
PR merge metrics
No merged PRs in 30d

Description

When using @libsql/client with Next.js (I've only tested in the app router), the client spits out a number of warnings about resolving modules.

Here's a small sample:

- warn ./node_modules/node-fetch/lib/index.js
Module not found: Can't resolve 'encoding' in '/workspace/node_modules/node-fetch/lib'

Import trace for requested module:
./node_modules/node-fetch/lib/index.js
./node_modules/cross-fetch/dist/node-ponyfill.js
./node_modules/@libsql/client/lib-esm/http/http-driver.js
./node_modules/@libsql/client/lib-esm/http/index.js
./app/db.ts
./app/page.tsx

You can see them in this reproduction sandbox. I've also copied the full set of warnings I'm seeing on a Vercel build below:

Show warnings from Vercel build output

[10:19:14.090] ./node_modules/.pnpm/node-fetch@2.6.12/node_modules/node-fetch/lib/index.js
[10:19:14.091] Module not found: Can't resolve 'encoding' in '/vercel/path0/node_modules/.pnpm/node-fetch@2.6.12/node_modules/node-fetch/lib'
[10:19:14.091] 
[10:19:14.091] Import trace for requested module:
[10:19:14.091] ./node_modules/.pnpm/node-fetch@2.6.12/node_modules/node-fetch/lib/index.js
[10:19:14.091] ./node_modules/.pnpm/@libsql+isomorphic-fetch@0.1.6/node_modules/@libsql/isomorphic-fetch/node.mjs
[10:19:14.091] ./node_modules/.pnpm/@libsql+hrana-client@0.5.0/node_modules/@libsql/hrana-client/lib-esm/index.js
[10:19:14.091] ./node_modules/.pnpm/@libsql+client@0.3.2/node_modules/@libsql/client/lib-esm/http.js
[10:19:14.097] ./src/lib/db.ts
[10:19:14.091] ./src/lib/auth.tsx
[10:19:14.092] 
[10:19:14.092] ./node_modules/.pnpm/node-fetch@2.6.12/node_modules/node-fetch/lib/index.js
[10:19:14.092] Module not found: Can't resolve 'encoding' in '/vercel/path0/node_modules/.pnpm/node-fetch@2.6.12/node_modules/node-fetch/lib'
[10:19:14.092] 
[10:19:14.092] Import trace for requested module:
[10:19:14.092] ./node_modules/.pnpm/node-fetch@2.6.12/node_modules/node-fetch/lib/index.js
[10:19:14.092] ./node_modules/.pnpm/@libsql+isomorphic-fetch@0.1.6/node_modules/@libsql/isomorphic-fetch/node.mjs
[10:19:14.092] ./node_modules/.pnpm/@libsql+hrana-client@0.5.0/node_modules/@libsql/hrana-client/lib-esm/index.js
[10:19:14.092] ./node_modules/.pnpm/@libsql+client@0.3.2/node_modules/@libsql/client/lib-esm/http.js
[10:19:14.097] ./src/lib/db.ts
[10:19:14.092] ./src/lib/auth.tsx
[10:19:14.092] 
[10:19:14.092] ./node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/buffer-util.js
[10:19:14.092] Module not found: Can't resolve 'bufferutil' in '/vercel/path0/node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib'
[10:19:14.092] 
[10:19:14.092] Import trace for requested module:
[10:19:14.092] ./node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/buffer-util.js
[10:19:14.093] ./node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/receiver.js
[10:19:14.093] ./node_modules/.pnpm/ws@8.13.0/node_modules/ws/wrapper.mjs
[10:19:14.093] ./node_modules/.pnpm/@libsql+isomorphic-ws@0.1.3/node_modules/@libsql/isomorphic-ws/node.mjs
[10:19:14.093] ./node_modules/.pnpm/@libsql+hrana-client@0.5.0/node_modules/@libsql/hrana-client/lib-esm/index.js
[10:19:14.093] ./node_modules/.pnpm/@libsql+client@0.3.2/node_modules/@libsql/client/lib-esm/http.js
[10:19:14.097] ./src/lib/db.ts
[10:19:14.093] ./src/lib/auth.tsx
[10:19:14.093] 
[10:19:14.093] ./node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/buffer-util.js
[10:19:14.093] Module not found: Can't resolve 'bufferutil' in '/vercel/path0/node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib'
[10:19:14.093] 
[10:19:14.093] Import trace for requested module:
[10:19:14.093] ./node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/buffer-util.js
[10:19:14.093] ./node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/receiver.js
[10:19:14.093] ./node_modules/.pnpm/ws@8.13.0/node_modules/ws/wrapper.mjs
[10:19:14.094] ./node_modules/.pnpm/@libsql+isomorphic-ws@0.1.3/node_modules/@libsql/isomorphic-ws/node.mjs
[10:19:14.094] ./node_modules/.pnpm/@libsql+hrana-client@0.5.0/node_modules/@libsql/hrana-client/lib-esm/index.js
[10:19:14.094] ./node_modules/.pnpm/@libsql+client@0.3.2/node_modules/@libsql/client/lib-esm/http.js
[10:19:14.097] ./src/lib/db.ts
[10:19:14.094] ./src/lib/auth.tsx
[10:19:14.094] 
[10:19:14.094] ./node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/validation.js
[10:19:14.094] Module not found: Can't resolve 'utf-8-validate' in '/vercel/path0/node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib'
[10:19:14.094] 
[10:19:14.094] Import trace for requested module:
[10:19:14.094] ./node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/validation.js
[10:19:14.094] ./node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/receiver.js
[10:19:14.094] ./node_modules/.pnpm/ws@8.13.0/node_modules/ws/wrapper.mjs
[10:19:14.094] ./node_modules/.pnpm/@libsql+isomorphic-ws@0.1.3/node_modules/@libsql/isomorphic-ws/node.mjs
[10:19:14.094] ./node_modules/.pnpm/@libsql+hrana-client@0.5.0/node_modules/@libsql/hrana-client/lib-esm/index.js
[10:19:14.094] ./node_modules/.pnpm/@libsql+client@0.3.2/node_modules/@libsql/client/lib-esm/http.js
[10:19:14.097] ./src/lib/db.ts
[10:19:14.095] ./src/lib/auth.tsx
[10:19:14.095] 
[10:19:14.095] ./node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/validation.js
[10:19:14.095] Module not found: Can't resolve 'utf-8-validate' in '/vercel/path0/node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib'
[10:19:14.095] 
[10:19:14.095] Import trace for requested module:
[10:19:14.095] ./node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/validation.js
[10:19:14.095] ./node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/receiver.js
[10:19:14.095] ./node_modules/.pnpm/ws@8.13.0/node_modules/ws/wrapper.mjs
[10:19:14.095] ./node_modules/.pnpm/@libsql+isomorphic-ws@0.1.3/node_modules/@libsql/isomorphic-ws/node.mjs
[10:19:14.095] ./node_modules/.pnpm/@libsql+hrana-client@0.5.0/node_modules/@libsql/hrana-client/lib-esm/index.js
[10:19:14.095] ./node_modules/.pnpm/@libsql+client@0.3.2/node_modules/@libsql/client/lib-esm/http.js
[10:19:14.097] ./src/lib/db.ts
[10:19:14.095] ./src/lib/auth.tsx
[10:19:14.095] 
[10:19:14.095] ./node_modules/.pnpm/better-sqlite3@8.5.2/node_modules/better-sqlite3/lib/database.js
[10:19:14.096] Critical dependency: the request of a dependency is an expression
[10:19:14.096] 
[10:19:14.096] Import trace for requested module:
[10:19:14.096] ./node_modules/.pnpm/better-sqlite3@8.5.2/node_modules/better-sqlite3/lib/database.js
[10:19:14.096] ./node_modules/.pnpm/better-sqlite3@8.5.2/node_modules/better-sqlite3/lib/index.js
[10:19:14.096] ./node_modules/.pnpm/@libsql+client@0.3.2/node_modules/@libsql/client/lib-esm/sqlite3.js
[10:19:14.096] ./node_modules/.pnpm/@libsql+client@0.3.2/node_modules/@libsql/client/lib-esm/node.js
[10:19:14.096] ./node_modules/.pnpm/drizzle-orm@0.28.5_@libsql+client@0.3.2_@opentelemetry+api@1.4.1/node_modules/drizzle-orm/libsql/index.mjs
[10:19:14.097] ./src/lib/db.ts
[10:19:14.096] ./src/lib/auth.tsx
[10:19:14.096] 
[10:19:14.096] ./node_modules/.pnpm/better-sqlite3@8.5.2/node_modules/better-sqlite3/lib/database.js
[10:19:14.096] Critical dependency: the request of a dependency is an expression
[10:19:14.096] 
[10:19:14.096] Import trace for requested module:
[10:19:14.096] ./node_modules/.pnpm/better-sqlite3@8.5.2/node_modules/better-sqlite3/lib/database.js
[10:19:14.096] ./node_modules/.pnpm/better-sqlite3@8.5.2/node_modules/better-sqlite3/lib/index.js
[10:19:14.096] ./node_modules/.pnpm/@libsql+client@0.3.2/node_modules/@libsql/client/lib-esm/sqlite3.js
[10:19:14.097] ./node_modules/.pnpm/@libsql+client@0.3.2/node_modules/@libsql/client/lib-esm/node.js
[10:19:14.097] ./node_modules/.pnpm/drizzle-orm@0.28.5_@libsql+client@0.3.2_@opentelemetry+api@1.4.1/node_modules/drizzle-orm/libsql/index.mjs
[10:19:14.097] ./src/lib/db.ts
[10:19:14.097] ./src/lib/auth.tsx
[10:19:14.097] 

It seems like these warnings all stem from the ws, node-fetch, and better-sqlite3 packages. I suspect it has something to do with how Webpack (which Next.js uses under the hood) resolves these modules, but I've never seen these errors for other packages.

One recommendation I might suggest for the node-fetch issues is consider using the new built-in fetch which is available since Node 18, or use undici, which is an official Node.js project, and I believe can be used to bring that fetch API to older versions.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction sandbox and the Next.js build output, then trace the reported imports through @libsql/client to node-fetch, ws, and better-sqlite3. Compare the warnings from the listed import traces and verify the completed change by confirming that the reported module-resolution and critical-dependency warnings no longer appear.

Written by the indexing model from the issue text.

Assessment

Tech stack
next.js, typescript, webpack
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.