cloudflare / next-on-pages

CLI to build and develop Next.js apps for Cloudflare Pages
https://www.npmjs.com/package/@cloudflare/next-on-pages
MIT License
1.16k stars 107 forks source link

[🐛 Bug]: @cloudflare/next-on-pages --watch keeps rebuilding with pnpm #212

Closed hambergerpls closed 1 year ago

hambergerpls commented 1 year ago

Cli version

0.10.1

next-on-pages environment related information

System: Platform: linux Arch: x64 Version: #1 SMP Fri Jan 27 02:56:13 UTC 2023 CPU: (16) x64 AMD Ryzen 7 5800H with Radeon Graphics Memory: 8 GB Shell: Unknown Binaries: Node: 18.16.0 Yarn: 1.22.19 npm: 9.5.1 pnpm: N/A Package Manager Used: pnpm Relevant Packages: @cloudflare/next-on-pages: 0.10.1 vercel: N/A next: N/A

Description

Running npx @cloudflare/next-on-pages --watch or pnpm next-on-pages --watch keeps rebuilding the project. Using npm works fine.

See below:

...
/test/my-app # pnpm dlx @cloudflare/next-on-pages --watch
.../share/pnpm/store/v3/tmp/dlx-1324     |  WARN  deprecated @npmcli/move-file@1.1.2
.../share/pnpm/store/v3/tmp/dlx-1324     |  WARN  deprecated rollup-plugin-inject@3.0.2
.../share/pnpm/store/v3/tmp/dlx-1324     |  WARN  deprecated sourcemap-codec@1.4.8
.../share/pnpm/store/v3/tmp/dlx-1324     | +775 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.../share/pnpm/store/v3/tmp/dlx-1324     | Progress: resolved 858, reused 775, downloaded 0, added 775, done
⚡️ @cloudflare/next-on-pages CLI v.0.10.1
⚡️ Detected Package Manager: pnpm
⚡️ Preparing project...
⚡️ Project is ready
⚡️ Building project...
▲  .../share/pnpm/store/v3/tmp/dlx-1358     | Progress: resolved 1, reused 0, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1358     | Progress: resolved 80, reused 78, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1358     | Progress: resolved 179, reused 160, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1358     | Progress: resolved 270, reused 243, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1358     |  WARN  deprecated @npmcli/move-file@1.1.2
▲  .../share/pnpm/store/v3/tmp/dlx-1358     | Progress: resolved 396, reused 345, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1358     |  WARN  deprecated rollup-plugin-inject@3.0.2
▲  .../share/pnpm/store/v3/tmp/dlx-1358     | Progress: resolved 554, reused 438, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1358     | Progress: resolved 714, reused 647, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1358     |  WARN  deprecated sourcemap-codec@1.4.8
▲  .../share/pnpm/store/v3/tmp/dlx-1358     | Progress: resolved 836, reused 773, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1358     | +774 ++++++++++++++++++++++++++++++++
▲  .../share/pnpm/store/v3/tmp/dlx-1358     | Progress: resolved 836, reused 774, downloaded 0, added 651
▲  .../share/pnpm/store/v3/tmp/dlx-1358     | Progress: resolved 836, reused 774, downloaded 0, added 774, done
▲  Vercel CLI 29.0.3
▲  Detected `pnpm-lock.yaml` version 6 generated by pnpm 8...
▲  WARNING: You should not upload the `.next` directory.
▲  Installing dependencies...
▲  Lockfile is up to date, resolution step is skipped
▲  Already up to date
▲  
▲  Done in 1.1s
▲  Detected Next.js version: 13.3.4
▲  Running "pnpm run build"
▲  > my-app@0.1.0 build /test/my-app
▲  > next build
▲  info  - Linting and checking validity of types...
▲  info  - Creating an optimized production build...
▲  info  - Compiled successfully
▲  info  - Collecting page data...
▲  info  - Generating static pages (0/3)
▲  info  - Generating static pages (3/3)
▲  info  - Finalizing page optimization...
▲  
▲  Route (pages)                              Size     First Load JS
▲  ┌ ○ /                                      4.53 kB        77.7 kB
▲  ├   └ css/977fe3ce042f91bf.css             1.89 kB
▲  ├   /_app                                  0 B            73.1 kB
▲  ├ ○ /404                                   182 B          73.3 kB
▲  └ ℇ /api/hello                             0 B            73.1 kB
▲  + First Load JS shared by all              73.8 kB
▲  ├ chunks/framework-ac88a2a245aea9ab.js   45.2 kB
▲  ├ chunks/main-f0f44bf05bc35991.js        26.9 kB
▲  ├ chunks/pages/_app-7a3eeff3d8d6257f.js  296 B
▲  ├ chunks/webpack-8fa1640cc84ba8fe.js     750 B
▲  └ css/876d048b5dab7c28.css               706 B
▲  ℇ  (Streaming)  server-side renders with streaming (uses React 18 SSR streaming or Server Components)
▲  ○  (Static)     automatically rendered as static HTML (uses no initial props)
▲  Collected static files (public/, static/, .next/static): 4.633ms
▲  Build Completed in .vercel/output [10s]
⚡️ Completed `pnpx vercel build`.
⚡️ Generated '.vercel/output/static/_worker.js'.
⚡️ Running in '--watch' mode. Awaiting changes... (Ctrl+C to exit.)"
⚡️ Detected Package Manager: pnpm
⚡️ Preparing project...
⚡️ Project is ready
⚡️ Building project...
▲  .../share/pnpm/store/v3/tmp/dlx-1531     | Progress: resolved 1, reused 0, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1531     | Progress: resolved 71, reused 70, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1531     | Progress: resolved 134, reused 115, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1531     | Progress: resolved 206, reused 187, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1531     | Progress: resolved 264, reused 244, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1531     |  WARN  deprecated @npmcli/move-file@1.1.2
▲  .../share/pnpm/store/v3/tmp/dlx-1531     | Progress: resolved 380, reused 339, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1531     | Progress: resolved 512, reused 471, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1531     |  WARN  deprecated rollup-plugin-inject@3.0.2
▲  .../share/pnpm/store/v3/tmp/dlx-1531     | Progress: resolved 642, reused 601, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1531     | Progress: resolved 774, reused 701, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1531     |  WARN  deprecated sourcemap-codec@1.4.8
▲  .../share/pnpm/store/v3/tmp/dlx-1531     | Progress: resolved 831, reused 769, downloaded 0, added 0
▲  .../share/pnpm/store/v3/tmp/dlx-1531     | +774 ++++++++++++++++++++++++++++++++
▲  .../share/pnpm/store/v3/tmp/dlx-1531     | Progress: resolved 836, reused 774, downloaded 0, added 3
▲  .../share/pnpm/store/v3/tmp/dlx-1531     | Progress: resolved 836, reused 774, downloaded 0, added 774, done
▲  Vercel CLI 29.0.3
▲  Detected `pnpm-lock.yaml` version 6 generated by pnpm 8...
▲  WARNING: You should not upload the `.next` directory.
▲  Installing dependencies...
▲  Lockfile is up to date, resolution step is skipped
▲  Already up to date
▲  
▲  Done in 1s
▲  Detected Next.js version: 13.3.4
▲  Running "pnpm run build"
▲  > my-app@0.1.0 build /test/my-app
▲  > next build
▲  info  - Linting and checking validity of types...
▲  info  - Creating an optimized production build...
▲  info  - Compiled successfully
▲  info  - Collecting page data...
▲  info  - Generating static pages (0/3)
▲  info  - Generating static pages (3/3)
▲  info  - Finalizing page optimization...
▲  
▲  Route (pages)                              Size     First Load JS
▲  ┌ ○ /                                      4.53 kB        77.7 kB
▲  ├   └ css/977fe3ce042f91bf.css             1.89 kB
▲  ├   /_app                                  0 B            73.1 kB
▲  ├ ○ /404                                   182 B          73.3 kB
▲  └ ℇ /api/hello                             0 B            73.1 kB
▲  + First Load JS shared by all              73.8 kB
▲  ├ chunks/framework-ac88a2a245aea9ab.js   45.2 kB
▲  ├ chunks/main-f0f44bf05bc35991.js        26.9 kB
▲  ├ chunks/pages/_app-7a3eeff3d8d6257f.js  296 B
▲  ├ chunks/webpack-8fa1640cc84ba8fe.js     750 B
▲  └ css/876d048b5dab7c28.css               706 B
▲  ℇ  (Streaming)  server-side renders with streaming (uses React 18 SSR streaming or Server Components)
▲  ○  (Static)     automatically rendered as static HTML (uses no initial props)
▲  Collected static files (public/, static/, .next/static): 5.082ms
▲  Build Completed in .vercel/output [9s]
⚡️ Completed `pnpx vercel build`.
⚡️ Generated '.vercel/output/static/_worker.js'.
⚡️ Running in '--watch' mode. Awaiting changes... (Ctrl+C to exit.)"
⚡️ Detected Package Manager: pnpm
⚡️ Preparing project...
⚡️ Project is ready
⚡️ Building project...
▲  .../share/pnpm/store/v3/tmp/dlx-1675     | Progress: resolved 1, reused 0, downloaded 0, added 0
...

Reproduction

npm install -g pnpm
pnpm create next-app@13.2.4
# Enter for all
cd my-app

edit pages/api/hello.ts to

==========
// Next.js Edge API Routes: https://nextjs.org/docs/api-routes/edge-api-routes

import type { NextRequest } from 'next/server'

export const config = {
  runtime: 'edge',
}

export default async function handler(req: NextRequest) {
    return new Response(JSON.stringify({ name: 'John Doe' }))
}
==========

pnpm dlx @cloudflare/next-on-pages --watch

Pages Deployment ID

No response

Pages Deployment Method

Direct Upload (wrangler pages publish or the @cloudflare/pages-action GitHub Action)

Additional Information

Not sure if it is only on my end as I'm using docker (node:18-alpine) as a dev container as I could not install pnpm in WSL. If it is working on native Linux, then this issue can be closed.

Would you like to help?

hambergerpls commented 1 year ago

Solved.

I noticed this code: https://github.com/cloudflare/next-on-pages/blob/d7e62c7fb99241565b41a664abfde29bbac99755/src/index.ts#L54C19-L67

Strangely my .pnpm-store was in my project folder, so it wasn't ignored.

All I did was changing my .pnpm-store directory with pnpm config set store-dir <new directory> , re-run npx @cloudflare/next-on-pages --watch and the problem is solved. 🤦

dario-piotrowicz commented 1 year ago

Awesome! :smiley:

So glad you managed to fix it, if you stumble across this again please reopen the issue and we can just extend the list of files we ignore accordingly, as it should be any easy change anyways :slightly_smiling_face: