tursodatabase / libsql

libSQL is a fork of SQLite that is both Open Source, and Open Contributions.
https://turso.tech/libsql
MIT License
11.31k stars 286 forks source link

cannot find libsql module with nextjs + sst #1436

Open gnllucena opened 5 months ago

gnllucena commented 5 months ago

libsql is not working with nextjs + sst:

versions: "sst": "^2.43.0", "@libsql/client": "^0.6.2",

found out this issue with similar problem: https://github.com/tursodatabase/libsql-client-ts/issues/186

the fix is not working for me:

import { Architecture } from "aws-cdk-lib/aws-lambda"
import { SSTConfig } from "sst"
import { NextjsSite } from "sst/constructs"

import { serverEnv } from "./src/serverEnv.mjs"

export default {
  config(_input) {
    return {
      name: "semnome027",
      region: "us-east-1",
      profile: "app-qa",
    }
  },
  stacks(app) {
    app.stack(function Site({ stack }) {
      const site = new NextjsSite(stack, "site", {
        cdk: { server: { architecture: Architecture.X86_64 } },
        runtime: "nodejs20.x",
        environment: {
          AWS_COGNITO_USERPOOL_CLIENT_ID:
            serverEnv.AWS_COGNITO_USERPOOL_CLIENT_ID,
          AWS_COGNITO_USERPOOL_ID: serverEnv.AWS_COGNITO_USERPOOL_ID,
          TURSO_DATABASE_URL: serverEnv.TURSO_DATABASE_URL,
          TURSO_DATABASE_TOKEN: serverEnv.TURSO_DATABASE_TOKEN,
        },
      })

      stack.addOutputs({
        SiteUrl: site.url,
      })
    })
  },
} satisfies SSTConfig
Cannot find module '@libsql/linux-x64-gnu' Require stack: - /var/task/node_modules/libsql/index.js - /var/task/node_modules/@libsql/client/lib-cjs/sqlite3.js - /var/task/node_modules/@libsql/client/lib-cjs/node.js - /var/task/.next/server/app/page.js - /var/task/node_modules/next/dist/server/require.js - /var/task/node_modules/next/dist/server/next-server.js
Error: Cannot find module '@libsql/linux-x64-gnu'
Require stack:
- /var/task/node_modules/libsql/index.js
- /var/task/node_modules/@libsql/client/lib-cjs/sqlite3.js
- /var/task/node_modules/@libsql/client/lib-cjs/node.js
- /var/task/.next/server/app/_not-found/page.js
- /var/task/node_modules/next/dist/server/require.js
- /var/task/node_modules/next/dist/server/next-server.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
    at /var/task/node_modules/next/dist/server/require-hook.js:55:36
    at Module._load (node:internal/modules/cjs/loader:981:27)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at mod.require (/var/task/node_modules/next/dist/server/require-hook.js:65:28)
    at require (node:internal/modules/helpers:177:18)
    at requireNative (/var/task/node_modules/libsql/index.js:22:10)
    at Object.<anonymous> (/var/task/node_modules/libsql/index.js:42:5)
    at Module._compile (node:internal/modules/cjs/loader:1364:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1422:10) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/var/task/node_modules/libsql/index.js',
    '/var/task/node_modules/@libsql/client/lib-cjs/sqlite3.js',
    '/var/task/node_modules/@libsql/client/lib-cjs/node.js',
    '/var/task/.next/server/app/_not-found/page.js',
    '/var/task/node_modules/next/dist/server/require.js',
    '/var/task/node_modules/next/dist/server/next-server.js'
  ],
  digest: '520410250'
}