vercel / next.js

The React Framework
https://nextjs.org
MIT License
127.46k stars 27.04k forks source link

[webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies #47394

Open DanielWahl opened 1 year ago

DanielWahl commented 1 year ago

Verify canary release

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP Debian 5.10.162-1 (2023-01-21)
    Binaries:
      Node: 16.19.1
      npm: 9.6.2
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.2.5-canary.12
      eslint-config-next: 13.2.4
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue

fresh/new create-next-app

To Reproduce

Simply creating a new Next.js project and running yarn build logs the following warning in the console:

npx create-next-app@latest
cd app-name
npm run build  // or yarn build

result: Bildschirmfoto 2023-03-22 um 13 41 14

Describe the Bug

It's probably linked to the issue 27650 and 35877, but it was not resolved, nor did any of this information help me fix this bug. On a freshly set-upped Debian server with the specs above, Next.js build throws the following error&warning-message (but not an error that cancels the build):

npm run build

> takeoff-frontend@0.1.0 build
> next build

info  - Loaded env from /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/.env.local
info  - Skipping linting
info  - Checking validity of types
info  - Creating an optimized production build ...    [webpack.cache.PackFileCacheStrategy] No pack exists at /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/.next/cache/webpack/server-production.pack: Error: ENOENT: no such file or directory, stat '/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/.next/cache/webpack/server-production/index.pack'
<t> [webpack.cache.PackFileCacheStrategy] restore cache container: 30.694241 ms
info  - Creating an optimized production build ..    [webpack.cache.PackFileCacheStrategy] Pack got invalid because of write to: Compilation/modules|/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/build/webpack/loaders/next-swc-loader.js??ruleSet[1].rules[1].oneOf[2].use!/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/pages/_app.tsx
    [webpack.cache.PackFileCacheStrategy] Storing pack...
    [webpack.cache.PackFileCacheStrategy] Capturing build dependencies... (/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/next.config.js, /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/, /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/build/webpack/loaders/next-swc-loader.js, /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/ignore-loader/index.js)
<t> [webpack.cache.PackFileCacheStrategy] resolve build dependencies: 44.93478 ms
    [webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Error snapshotting file timestamp hash combination of /usr/www/users: Error: EACCES: permission denied, open '/usr/www/users'
<t> [webpack.cache.PackFileCacheStrategy] snapshot build dependencies: 0.941732 ms
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies
    [webpack.cache.PackFileCacheStrategy] Error: Unable to snapshot resolve dependencies
        at /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:553124
        at jobError (/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:276218)
        at /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:277146
        at /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:289658
        at /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:1302194
        at Hook.eval [as callAsync] (eval at create (/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:13:28771), <anonymous>:6:1)
        at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:13:25925)
        at AsyncQueue._handleResult (/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:1301742)
        at /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:1301593
        at ReadFileContext.<anonymous> (/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:289057)
    [webpack.cache.PackFileCacheStrategy] No pack exists at /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/.next/cache/webpack/edge-server-production.pack: Error: ENOENT: no such file or directory, stat '/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/.next/cache/webpack/edge-server-production/index.pack'
<t> [webpack.cache.PackFileCacheStrategy] restore cache container: 14.656235 ms
    [webpack.cache.PackFileCacheStrategy] No pack exists at /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/.next/cache/webpack/client-production.pack: Error: ENOENT: no such file or directory, stat '/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/.next/cache/webpack/client-production/index.pack'
<t> [webpack.cache.PackFileCacheStrategy] restore cache container: 6.988857 ms
info  - Creating an optimized production build .    [webpack.cache.PackFileCacheStrategy] Pack got invalid because of write to: Compilation/modules|/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/build/webpack/loaders/next-client-pages-loader.js?absolutePagePath=private-next-pages%2F_app.tsx&page=%2F_app!
    [webpack.cache.PackFileCacheStrategy] Storing pack...
    [webpack.cache.PackFileCacheStrategy] Capturing build dependencies... (/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/next.config.js, /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/, /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/build/webpack/loaders/next-client-pages-loader.js, /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/build/webpack/loaders/next-swc-loader.js, /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js, /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js, /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/build/webpack/loaders/resolve-url-loader/index.js, /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/sass-loader/cjs.js, /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/mini-css-extract-plugin/loader.js)
<t> [webpack.cache.PackFileCacheStrategy] resolve build dependencies: 78.69155 ms
    [webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Error snapshotting file timestamp hash combination of /usr/www/users: Error: EACCES: permission denied, open '/usr/www/users'
<t> [webpack.cache.PackFileCacheStrategy] snapshot build dependencies: 0.703472 ms
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies
    [webpack.cache.PackFileCacheStrategy] Error: Unable to snapshot resolve dependencies
        at /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:553124
        at jobError (/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:276218)
        at /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:277146
        at /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:289658
        at /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:1302194
        at Hook.eval [as callAsync] (eval at create (/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:13:28771), <anonymous>:6:1)
        at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:13:25925)
        at AsyncQueue._handleResult (/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:1301742)
        at /usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:1301593
        at ReadFileContext.<anonymous> (/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules/next/dist/compiled/webpack/bundle5.js:28:289057)
info  - Compiled successfully
info  - Collecting page data
info  - Generating static pages (12/12)
info  - Finalizing page optimization

Route (pages)                              Size     First Load JS
┌ ○ / (484 ms)                             2.18 kB         110 kB
├   /_app                                  0 B              74 kB
├ ○ /404 (540 ms)                          1.77 kB         109 kB
├ ○ /500 (494 ms)                          1.77 kB         109 kB
└ λ /api/hello                             0 B              74 kB
+ First Load JS shared by all              88.6 kB
  ├ chunks/framework-cda2f1305c3d9424.js   45.2 kB
  ├ chunks/main-75b811eb5316bd1a.js        27.7 kB
  ├ chunks/pages/_app-fc698ddf2bb24351.js  297 B
  ├ chunks/webpack-8fa1640cc84ba8fe.js     750 B
  └ css/e90b5e437a2ca258.css               14.6 kB

λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
○  (Static)  automatically rendered as static HTML (uses no initial props)

info  - Creating an optimized production build ..

In the result above, there's also an error Error: EACCES: permission denied, open '/usr/www/users'. The linux user is not a superuser, so has no access to this folder, but this should not prevent the build from being successful.

After this build and exposing the webpage to a port (I can also send a link to test), the homepage "/" shows an 404 error, but the styling, some components like navigation, ... (on a non-fresh build) shows.

This is the content of Bildschirmfoto 2023-03-22 um 13 52 00 the .next/cache folder:

Expected Behavior

The build should be finished without any warning/error.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Startet an pm2 process with a proxypass pointing to the port.

DanielWahl commented 1 year ago

Not quite sure if that's the root of the problem, but webpack is trying to access the base root folder of the server:

Set(8) {
  '/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend/node_modules',
  '/usr/www/users/takeoff/takeoffshow.blocknote.dev/takeoff-frontend',
  '/usr/www/users/takeoff/takeoffshow.blocknote.dev',
  '/usr/www/users/takeoff',
  '/usr/www/users',
  '/usr/www',
  '/usr',
  '/'
}

The file causing this: lib/FileSystemInfo.js:2055 --> processCapturedFiles

richleach commented 1 year ago

any luck with this bug? I'm getting the same error on my Mac environment (MacOS Big Sur 11.7.4 Node v 16.17.0 npm v 9.6.2)

richleach commented 1 year ago

just curious, did you start getting this error after you installed tailwindcss? That's when my troubles started.... Could just be a coincidence

DanielWahl commented 1 year ago

Still didn't find a solution to the problem. I'm currently not using TailwindCSS, the problem occurs even after a completely fresh Next.js install on the server.

richleach commented 1 year ago

Yeah, I'm now getting the problem with completely fresh Next.js installs too. I made sure my Node and NPM were up to date (per the Next.js docs), trying to work this problem....

richleach commented 1 year ago

... but oddly my site is loading locally just fine, not even any errors in the browser console, just that webpack error in my server console

semy commented 1 year ago

I had the same today when I try building on vercel:

info - Creating an optimized production build... 20:05:01.655 | [webpack.cache.PackFileCacheStrategy] Serializing big strings (659kiB) impacts deserialization performance (consider using Buffer instead and decode when needed) 20:05:08.248 | warn - Compiled with warnings 20:05:08.248

When I build locally I see sometimes the same warning.

karlo-humanmanaged commented 1 year ago

I have the same error:

Attention: Next.js now collects completely anonymous telemetry regarding usage.
This information is used to shape Next.js' roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://nextjs.org/telemetry

- info Linting and checking validity of types...
- info Creating an optimized production build...
<w> [webpack.cache.PackFileCacheStrategy] Serializing big strings (659kiB) impacts deserialization performance (consider using Buffer instead and decode when needed)
- warn Compiled with warnings

../../../node_modules/.pnpm/next@13.4.2_3j7hb26pwgm6spbxoejtjx6xja/node_modules/next/dist/server/web/spec-extension/image-response.js
A Node.js API is used (process.turbopack at line: 14) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime

Import trace for requested module:
../../../node_modules/.pnpm/next@13.4.2_3j7hb26pwgm6spbxoejtjx6xja/node_modules/next/dist/server/web/spec-extension/image-response.js
../../../node_modules/.pnpm/next@13.4.2_3j7hb26pwgm6spbxoejtjx6xja/node_modules/next/server.js
../../../node_modules/.pnpm/next-auth@4.22.1_cmp7sjki5xcmfyvhcokzzink7a/node_modules/next-auth/next/middleware.js
../../../node_modules/.pnpm/next-auth@4.22.1_cmp7sjki5xcmfyvhcokzzink7a/node_modules/next-auth/middleware.js
mkmrcodes commented 1 year ago

same error with version 13.4

JuniorAlbuquerque commented 1 year ago

in my case, I fixed it like this:

WesleyRafaelp commented 1 year ago

did anyone manage to solve it? I have the same problem

prodkt commented 1 year ago

@WesleyRafaelp same issue persists here as well, Wes.

ucefkh commented 1 year ago

what is this weird problem? C'mon Vercel and next team

ucefkh commented 1 year ago

Resting everything solves it, at least for now

kimhwanhoon commented 1 year ago

Same

unhandledRejection: [Error: ENOENT: no such file or directory, stat '/Users/.../.next/cache/webpack/server-development/0.pack.gz'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'stat',
  path: '/Users/.../.next/cache/webpack/server-development/0.pack.gz'
}
PeterCastilloG commented 1 year ago

same error

Maxdoggydog commented 1 year ago

in my case, I fixed it like this:

  • remove node_modules, lockfile and .next folder
  • install dependencies again and run app

It worked for me, thanks. I was removing the "node_modules" but not "package-lock.json".

fernandezAmor commented 1 year ago

in my case, I fixed it like this:

  • remove node_modules, lockfile and .next folder
  • install dependencies again and run app

This worked for me too, no need to remove lockfile but node_modules and .next folder. Thanks!!

Maxdoggydog commented 1 year ago

in my case, I fixed it like this:

  • remove node_modules, lockfile and .next folder
  • install dependencies again and run app

This worked for me too, no need to remove lockfile but node_modules and .next folder. Thanks!!

I had removed the ".next" and "node_modules" but I was still getting this error, but I when I removed "lockfile", it worked.

IDNK2203 commented 1 year ago

in my case, I fixed it like this:

  • remove node_modules, lockfile and .next folder
  • install dependencies again and run app

Worked for me

juliocarneiro commented 1 year ago

in my case, I fixed it like this:

  • remove node_modules, lockfile and .next folder
  • install dependencies again and run app

work for me too

wjbetech commented 12 months ago

Not working for me. Have done all efforts advised here.

developerwill commented 10 months ago

I'm expericing the same [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies, does anyone have a fix? Removing node_modules, lockfile and .next folder and re-installing dependencies didn't work for me.

keisokoo commented 10 months ago

Same warning. [webpack.cache.PackFileCacheStrategy] Skipped not serializable cache item ...

In my case, it occurs in css-loader, postcss-loader and vanilla-extract-webpack-plugin. even i'm using swc...

josemsb92 commented 10 months ago

I have also deleted the 'node_modules,' '.next/' folder, and lock file, and reinstalled them. However, I am still encountering the following warning:

[webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies.

demirtasdurmus commented 10 months ago

[webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies

Same for me as well, tried everything advised here including rm -rf .next & rm -rf node_modules & rm -rf package-lock.json and npm i again. None of them worked unfortunately.

ikhsanytc commented 9 months ago

i got the same error but in my windows not in linux, i move the dir project to C and its run normally.

tomato-ga commented 7 months ago

I am using tailwind css.

The same problem appears randomly after deleting /node_modules / .next / package-lock.json and restarting the server.

When this error occurs, the CSS is disabled.

JakeCasey commented 7 months ago

I was having this issue, alongside an issue with next yelling about EOF errors. Cleaning out .next, node_modules, and package-lock.json, and then upgrading from node v20.9.0 to v21.7.3 fixed it for me.

Ymirke commented 7 months ago

I was unable to remove this warning.

What I tried:

I did fix it however, but passing in --turbo to just use turbopack instead.

MostafaKMilly commented 1 month ago

Still having this issue

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

mio-19 commented 1 month ago

I had this issue after upgrading node from 22 to node.js23

h-behgam commented 1 month ago

I had this issue after upgrading node to ver 23 . After downgrade, solved it.

longfellowone commented 1 month ago

Also getting this in v23, downgrading to 22 fixes it

j-fdion commented 1 month ago

Also getting this in v23, downgrading to 22 fixes it

Worked for me, thank you! @h-behgam & @longfellowone

yonisetiawan commented 1 month ago

in my case, I fixed it like this:

  • remove node_modules, lockfile and .next folder
  • install dependencies again and run app

its work, firts you can try remote node_modules and .next folder

mio-19 commented 1 month ago

I tried removing node_modules and .next. still:


  ▲ Next.js 15.0.1

   Creating an optimized production build ...
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies
flawnn commented 1 month ago

Also getting this in v23, downgrading to 22 fixes it

Interesting - probably not supported yet?

oidualc commented 3 weeks ago

Same for me, using NextJS 14.2.16 and upgrading from Node v22.x.x to v23.0.0 (or even v23.1.0) results in this warning and a broken build. It's probably best to open a specific issue about Node 23 support.

Mindgames commented 3 weeks ago

Also getting this in v23, downgrading to 22 fixes it

👉 This solved it for me - MacOS

This is a odd issue and the warnings + possible fixes found when searching are a bit misleading

Pnlvfx commented 3 weeks ago

same for me in nodejs 23 and latest next canary

Melvynx commented 2 weeks ago

Yes, the only way is to downgrade to NodeJS 21 or 22 to fix the problems when using NextJS 15

harisiqbal12 commented 2 weeks ago

downgrading to v22 works for me.

adnan-smlatic commented 1 week ago

Same for me, using NextJS 14.2.16 and upgrading from Node v22.x.x to v23.0.0 (or even v23.1.0) results in this warning and a broken build. It's probably best to open a specific issue about Node 23 support.

Thank you so much! I had the same error on MacOS 14.5 - Next.js 14.2.18, downgrading node from v23.1.0 to v22.11.0 fixed it.

Downgrade guide

klaygomes commented 6 days ago

Same issue here.

Doesn't work on version v23

node --version
v23.1.0

After I downgraded to:

node --version 
v22.11.0

Worked fine.

-- specs MacOs: Version 15.1.1 (24B91) webpack": "^5.96.1" next: "^14.2.17", Typescript: