Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module '@libsql/darwin-arm64' in standalone build #10484

Open
janeumnn opened this issue Jan 9, 2025 · 4 comments
Open

Cannot find module '@libsql/darwin-arm64' in standalone build #10484

janeumnn opened this issue Jan 9, 2025 · 4 comments
Labels
db: sqlite status: needs-triage Possible bug which hasn't been reproduced yet

Comments

@janeumnn
Copy link

janeumnn commented Jan 9, 2025

Describe the Bug

Hi,

I am trying to get a standalone build working with @payloadcms/db-sqlite. However, neither running the build natively nor using a container with the provided Dockerfile template works for me. For example, when I attempt to access the initial /admin/create-first-user route after starting the native build, I encounter the following error:

# node server.js
   ▲ Next.js 15.1.4
   - Local:        http://localhost:3000
   - Network:      http://0.0.0.0:3000

 ✓ Starting...
 ✓ Ready in 243ms
[Error: Cannot find module '@libsql/darwin-arm64'
Require stack:
- /Users/***/***/app/node_modules/.pnpm/[email protected]/node_modules/libsql/index.js] {
  code: 'MODULE_NOT_FOUND',
  requireStack: [Array]
}
 ⨯ unhandledRejection:  [Error: Cannot find module '@libsql/darwin-arm64'
Require stack:
- /Users/***/***/app/node_modules/.pnpm/[email protected]/node_modules/libsql/index.js] {
  code: 'MODULE_NOT_FOUND',
  requireStack: [Array]
}

I have also tried including @libsql/client and libsql as project dependencies, as previously mentioned in #7527, it did not resolve the issue for me. Upon inspecting the node_modules directory in the resulting build, I noticed that the prebuilt binary package for @libsql is missing. This leads me to suspect that the issue might be related to the standalone bundling process in Next.js.

@DanRibbens

Link to the code that reproduces this issue

https://github.com/janeumnn/payload-reproduction-bug

Reproduction Steps

  1. Clone the repository.
  2. Navigate to the project directory: cd payload-reproduction-bug && pnpm install.
  3. Build the project: pnpm build.
  4. Copy the static assets: cp -r .next/static .next/standalone/.next/.
  5. Move the standalone folder to a different location to avoid interference with the installed project dependencies.
  6. Navigate to the new location of the standalone build.
  7. Start the server: node server.js.

Which area(s) are affected? (Select all that apply)

db-sqlite

Environment Info

Node.js v20.14.0

Binaries:
  Node: 20.14.0
  npm: 10.7.0
  Yarn: N/A
  pnpm: 9.1.3
Relevant Packages:
  payload: 3.15.1
  next: 15.1.0
  @payloadcms/db-sqlite
  @payloadcms/email-nodemailer: 3.15.1
  @payloadcms/graphql: 3.15.1
  @payloadcms/next/utilities: 3.15.1
  @payloadcms/payload-cloud: 3.15.1
  @payloadcms/richtext-lexical: 3.15.1
  @payloadcms/translations: 3.15.1
  @payloadcms/ui/shared: 3.15.1
  react: 19.0.0
  react-dom: 19.0.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.2.0: Fri Dec  6 19:01:59 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 8
@janeumnn janeumnn added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Jan 9, 2025
@harrykeightley
Copy link

harrykeightley commented Jan 24, 2025

Hello, just a fix that worked for me ...
my next.config.mjs:

import path from 'path'
import { fileURLToPath } from 'url'
import { withPayload } from '@payloadcms/next/withPayload'
const __dirname = fileURLToPath(new URL('.', import.meta.url))

/** @type {import('next').NextConfig} */
const nextConfig = {
  // Your Next.js config here
  output: 'standalone',
  outputFileTracingRoot: path.join(__dirname, '../../'),
  outputFileTracingIncludes: {
    '/admin/*': [
      '../../node_modules/@libsql/**/*',
    ],
  },
}

export default withPayload(nextConfig)

my root .npmrc in my monorepo:

public-hoist-pattern[]=*@libsql*

my dockerfile in my payload subdirectory (using pnpm for a monorepo)

FROM node:22.12.0-alpine AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

FROM base AS builder
WORKDIR /app
COPY . .
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run --filter=cms build

FROM base AS runner
WORKDIR /app
RUN apk add bash

ENV NODE_ENV="production"
ENV NEXT_TELEMETRY_DISABLED=1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/apps/cms/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/apps/cms/.next/static /app/apps/cms/.next/static


USER nextjs

ENV PORT 3000
EXPOSE $PORT

CMD HOSTNAME="0.0.0.0" node apps/cms/server.js

Now why does this work?

  • I hoist up the package @libsql/platform-specific-something-or-rather,
  • then we make sure that nextjs properly sees this by adding in that outputFileTracingINcludes stuff.
  • Then we build.
    I hope this solution may save the next poor soul some time.

@janeumnn
Copy link
Author

janeumnn commented Jan 25, 2025

Thanks a lot! This works for me in my monorepo setup too. Since this issue is related to Next.js itself, and it happens even in a standalone build without PayloadCMS being integrated, this can be closed here.

EDIT:
Additionally, when connecting to Turso, the following path should also be included in outputFileTracingIncludes within next.config.js:

'/api/*': ['../../node_modules/@libsql/**/*']

Otherwise, the API routes will not be able to resolve that module.

@hustlersambitionz4
Copy link

node server.js

▲ Next.js 15.1.4

✓ Starting...
✓ Ready in 243ms
[Error: Cannot find module '@libsql/darwin-arm64'
Require stack:

  • /Users///app/node_modules/.pnpm/[email protected]/node_modules/libsql/index.js] {
    code: 'MODULE_NOT_FOUND',
    requireStack: [Array]
    }
    ⨯ unhandledRejection: [Error: Cannot find module '@libsql/darwin-arm64'
    Require stack:
  • /Users///app/node_modules/.pnpm/[email protected]/node_modules/libsql/index.js] {
    code: 'MODULE_NOT_FOUND',
    requireStack: [Array]
    }images/my-profile-file.pngimages/pull-request-branches.pngimages/profile-readme-example.pngimages/main-branch-dropdown.pnghttp://0.0.0.0:3000

@hustlersambitionz4
Copy link

15.1.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
db: sqlite status: needs-triage Possible bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

4 participants