timlrx / contentlayer2

Contentlayer turns your content into data - making it super easy to import MD(X) and CMS content in your app
https://contentlayer.dev
MIT License
173 stars 11 forks source link

TypeError: Cannot read properties of undefined (reading 'cwd') #42

Open dariusz-wozniak opened 1 week ago

dariusz-wozniak commented 1 week ago

Hi, I updated my project to contentlayer2, but I'm receiving an error during Vercel deployment.

Here are more details:

Error:

This error shouldn't have happened. Please consider opening a GitHub issue with the stack trace below here:
https://github.com/timlrx/contentlayer2/issues
An unchecked error was produced.
TypeError: Cannot read properties of undefined (reading 'cwd')
    at f (file:///vercel/path0/node_modules/@contentlayer/core/src/cwd.ts:24:53)
    at f (file:///vercel/path0/node_modules/@effect-ts/system/_src/Effect/has.ts:121:43)
    at IRead.f (file:///vercel/path0/node_modules/@effect-ts/system/_src/Effect/has.ts:113:33)
    at FiberContext.evaluateNow (file:///vercel/path0/node_modules/@effect-ts/system/_src/Fiber/context.ts:1136:31)
    at file:///vercel/path0/node_modules/@effect-ts/system/_src/Fiber/context.ts:576:33
    at file:///vercel/path0/node_modules/@effect-ts/system/_src/Support/Scheduler/index.ts:15:9
Fiber: #0 (started at: 2024-10-08T19:54:50.619Z) was supposed to continue to: <empty trace>
Fiber: #0 (started at: 2024-10-08T19:54:50.619Z) Execution trace: <empty trace>
Fiber: #0 (started at: 2024-10-08T19:54:50.619Z) was spawned by: <empty trace>
OS: linux 5.10.174 (arch: x64)
Process: /node20/bin/node /vercel/path0/node_modules/.bin/next build
Node version: v20.17.0
Contentlayer version: 0.5.1
Error: Command "npm run build" exited with 1

Branch I'm trying to upgrade contentlayer v1 to v2:

https://github.com/dariusz-wozniak/dariuszwozniak.net-v2/pull/67

Do you know what's the cause of the issue and how to fix that?

jonbranan commented 3 days ago

I am having the same issue via a different deployment method. I am trying to build a docker container locally on my laptop.

Here is the repository I am attempting to build from: https://git.jonb.io/jblu/jonbio

Here is the docker file:

FROM node:18-alpine AS base

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
  if [ -f yarn.lock ]; then yarn --immutable; \
  elif [ -f package-lock.json ]; then npm ci; \
  elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
  else echo "Lockfile not found." && exit 1; \
  fi

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

ENV NEXT_TELEMETRY_DISABLED=1

RUN \
  if [ -f yarn.lock ]; then yarn build; \
  elif [ -f package-lock.json ]; then npm run build; \
  elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
  else echo "Lockfile not found." && exit 1; \
  fi

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED=1

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

COPY --from=builder /app/public ./public

# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next

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

USER nextjs

EXPOSE 3000

ENV PORT=3000

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]

And this is the error I am getting:

jonb@Jonathans-MBP jonb.io % docker build -t jonbio .
[+] Building 11.4s (16/21)                                                                                                                         docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                               0.0s
 => => transferring dockerfile: 2.07kB                                                                                                                             0.0s
 => [internal] load metadata for docker.io/library/node:18-alpine                                                                                                  0.6s
 => [auth] library/node:pull token for registry-1.docker.io                                                                                                        0.0s
 => [internal] load .dockerignore                                                                                                                                  0.0s
 => => transferring context: 2B                                                                                                                                    0.0s
 => [internal] load build context                                                                                                                                  2.2s
 => => transferring context: 50.74MB                                                                                                                               2.0s
 => [base 1/1] FROM docker.io/library/node:18-alpine@sha256:02376a266c84acbf45bd19440e08e48b1c8b98037417334046029ab585de03e2                                       0.0s
 => => resolve docker.io/library/node:18-alpine@sha256:02376a266c84acbf45bd19440e08e48b1c8b98037417334046029ab585de03e2                                            0.0s
 => CACHED [builder 1/4] WORKDIR /app                                                                                                                              0.0s
 => CACHED [runner 2/8] RUN addgroup --system --gid 1001 nodejs                                                                                                    0.0s
 => CACHED [runner 3/8] RUN adduser --system --uid 1001 nextjs                                                                                                     0.0s
 => CACHED [deps 1/4] RUN apk add --no-cache libc6-compat                                                                                                          0.0s
 => CACHED [deps 2/4] WORKDIR /app                                                                                                                                 0.0s
 => CACHED [deps 3/4] COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./                                                                           0.0s
 => CACHED [deps 4/4] RUN   if [ -f yarn.lock ]; then yarn --immutable;   elif [ -f package-lock.json ]; then npm ci;   elif [ -f pnpm-lock.yaml ]; then corepack  0.0s
 => CACHED [builder 2/4] COPY --from=deps /app/node_modules ./node_modules                                                                                         0.0s
 => [builder 3/4] COPY . .                                                                                                                                         5.9s
 => ERROR [builder 4/4] RUN   if [ -f yarn.lock ]; then yarn build;   elif [ -f package-lock.json ]; then npm run build;   elif [ -f pnpm-lock.yaml ]; then corep  2.6s
------
 > [builder 4/4] RUN   if [ -f yarn.lock ]; then yarn build;   elif [ -f package-lock.json ]; then npm run build;   elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build;   else echo "Lockfile not found." && exit 1;   fi:
1.029   ▲ Next.js 14.2.3
1.030 
1.044    Creating an optimized production build ...
2.487 This error shouldn't have happened. Please consider opening a GitHub issue with the stack trace below here:
2.487 https://github.com/timlrx/contentlayer2/issues
2.487 
2.487 An unchecked error was produced.
2.487 
2.487 TypeError: Cannot read properties of undefined (reading 'cwd')
2.487     at f (file:///app/node_modules/contentlayer2/node_modules/@contentlayer2/core/src/cwd.ts:24:53)
2.487     at f (file:///app/node_modules/@effect-ts/system/_src/Effect/has.ts:121:43)
2.487     at IRead.f (file:///app/node_modules/@effect-ts/system/_src/Effect/has.ts:113:33)
2.487     at FiberContext.evaluateNow (file:///app/node_modules/@effect-ts/system/_src/Fiber/context.ts:1136:31)
2.487     at file:///app/node_modules/@effect-ts/system/_src/Fiber/context.ts:576:33
2.487     at file:///app/node_modules/@effect-ts/system/_src/Support/Scheduler/index.ts:15:9
2.487 
2.487 Fiber: #0 (started at: 2024-10-15T20:38:21.622Z) was supposed to continue to: <empty trace>
2.487 
2.487 Fiber: #0 (started at: 2024-10-15T20:38:21.622Z) Execution trace: <empty trace>
2.487 
2.487 Fiber: #0 (started at: 2024-10-15T20:38:21.622Z) was spawned by: <empty trace>
2.488 
2.488 OS: linux 6.10.4-linuxkit (arch: arm64)
2.488 Process: /usr/local/bin/node /app/node_modules/next/dist/bin/next build
2.488 Node version: v18.20.4
2.488 Contentlayer version: 0.5.1
2.488 
------
Dockerfile:27
--------------------
  26 |     
  27 | >>> RUN \
  28 | >>>   if [ -f yarn.lock ]; then yarn build; \
  29 | >>>   elif [ -f package-lock.json ]; then npm run build; \
  30 | >>>   elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
  31 | >>>   else echo "Lockfile not found." && exit 1; \
  32 | >>>   fi
  33 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c if [ -f yarn.lock ]; then yarn build;   elif [ -f package-lock.json ]; then npm run build;   elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build;   else echo \"Lockfile not found.\" && exit 1;   fi" did not complete successfully: exit code: 1

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/ewoyqgjvzgaazags9ih4exv63

I can sucessfully build externally outside of the docker container:

jonb@Jonathans-MBP jonb.io % yarn build              
  ▲ Next.js 14.2.3

   Creating an optimized production build ...
(node:39904) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
successCallback /Users/jonb/code/jonb.io/.contentlayer
(node:39904) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
Local search index generated...
Generated 8 documents in .contentlayer
 ✓ Compiled successfully
   Linting and checking validity of types  . ⚠ TypeScript project references are not fully supported. Attempting to build in incremental mode.
 ✓ Linting and checking validity of types    
 ✓ Collecting page data    
 ✓ Generating static pages (27/27)
 ✓ Collecting build traces    
 ✓ Finalizing page optimization    

Route (app)                                  Size     First Load JS
┌ ○ /                                        1.12 kB          95 kB
├ ○ /_not-found                              136 B          87.3 kB
├ ○ /about                                   293 B          92.5 kB
├ ƒ /api/newsletter                          0 B                0 B
├ ○ /blog                                    136 B           101 kB
├ ● /blog/[...slug]                          6.07 kB         105 kB
├   ├ /blog/code-sample
├   ├ /blog/github-markdown-guide
├   ├ /blog/guide-to-using-images-in-nextjs
├   └ [+4 more paths]
├ ● /blog/page/[page]                        136 B           101 kB
├   ├ /blog/page/1
├   └ /blog/page/2
├ ○ /projects                                184 B          99.2 kB
├ ○ /robots.txt                              0 B                0 B
├ ○ /sitemap.xml                             0 B                0 B
├ ○ /tags                                    176 B          94.1 kB
└ ● /tags/[tag]                              136 B           101 kB
    ├ /tags/github
    ├ /tags/guide
    ├ /tags/next-js
    └ [+4 more paths]
+ First Load JS shared by all                87.1 kB
  ├ chunks/23-ee23754aea40848f.js            31.5 kB
  ├ chunks/fd9d1056-7b6151dbf9b37af2.js      53.7 kB
  └ other shared chunks (total)              2 kB

○  (Static)   prerendered as static content
●  (SSG)      prerendered as static HTML (uses getStaticProps)
ƒ  (Dynamic)  server-rendered on demand

(node:39962) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
RSS feed generated...
timlrx commented 3 days ago

@dariusz-wozniak a few errors: