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

[webpack.cache.PackFileCacheStrategy] error when using next.config.mjs #33693

Closed
iAdramelk opened this issue Jan 26, 2022 · 20 comments
Closed

[webpack.cache.PackFileCacheStrategy] error when using next.config.mjs #33693

iAdramelk opened this issue Jan 26, 2022 · 20 comments
Labels
linear: next Confirmed issue that is tracked by the Next.js team. locked Webpack Related to Webpack with Next.js.

Comments

@iAdramelk
Copy link

iAdramelk commented Jan 26, 2022

Run next info (available from version 12.0.8 and up)

    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:41 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T6000
    Binaries:
      Node: 17.3.1
      npm: 8.3.0
      Yarn: 1.22.17
      pnpm: 6.27.1
    Relevant packages:
      next: 12.0.8
      react: 17.0.2
      react-dom: 17.0.2

But can be reproduced on Vercel builds using node@14.

What version of Next.js are you using?

12.0.8

What version of Node.js are you using?

17.3.1

What browser are you using?

Server error

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

When using esmodules via next.config.mjs, IF config contains custom webpack config AND IF there are some imports from the node system libraries like path or fs, webpack will start throwing cache warnings in dev and build modes.

Expected Behavior

No errors in the CLI and working cache.

To Reproduce

  1. Create new project with yarn create next-app.
  2. Rename config to next.config.mjs.
  3. Paste the following code inside the config file:
import { resolve } from "path";

export default {
  webpack: (config) => config
};

Now, then you try to run the project, you will get the following warnings in the CLI:

<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Can't resolve 'path' in '/Users/iadramelk/Projects/next-mjs-bug'
<w> while resolving 'path' in /Users/iadramelk/Projects/next-mjs-bug as file
<w>  at resolve esm file path
<w>  at file dependencies /Users/iadramelk/Projects/next-mjs-bug/next.config.mjs
<w>  at file /Users/iadramelk/Projects/next-mjs-bug/next.config.mjs
<w>  at resolve commonjs /Users/iadramelk/Projects/next-mjs-bug/next.config.mjs
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Can't resolve 'path' in '/Users/iadramelk/Projects/next-mjs-bug'
<w> while resolving 'path' in /Users/iadramelk/Projects/next-mjs-bug as file
<w>  at resolve esm file path
<w>  at file dependencies /Users/iadramelk/Projects/next-mjs-bug/next.config.mjs
<w>  at file /Users/iadramelk/Projects/next-mjs-bug/next.config.mjs
<w>  at resolve commonjs /Users/iadramelk/Projects/next-mjs-bug/next.config.mjs

NEXT-1395

@iAdramelk iAdramelk added the bug Issue was opened via the bug report template. label Jan 26, 2022
@stefanprobst
Copy link
Contributor

see #30870 (comment) for a tip how to silence the warnings.

@iAdramelk
Copy link
Author

@stefanprobst thank for the tip! Will silence them until it is resolved.

@balazsorban44 balazsorban44 added Webpack Related to Webpack with Next.js. kind: bug and removed bug Issue was opened via the bug report template. labels Jan 27, 2022
@balazsorban44 balazsorban44 changed the title [webpack.cache.PackFileCacheStrategy] error then using next.config.mjs [webpack.cache.PackFileCacheStrategy] error when using next.config.mjs Jan 27, 2022
@SimenB
Copy link

SimenB commented Mar 8, 2022

Webpack does this outside of next, might be better to file an issue in https://github.com/webpack/webpack?

@mrchief
Copy link

mrchief commented Mar 19, 2022

Webpack does this outside of next, might be better to file an issue in webpack/webpack?

There is webpack/webpack#14645

@FunctionDJ
Copy link

should be solved in latest webpack version. feel free to create repro.

- webpack/webpack#14645 (reply in thread)

I hope a Next.js update will raise the Webpack version to fix this 🙏

@SimenB
Copy link

SimenB commented Mar 28, 2022

This is still an issue in webpack 5.70, fwiw, so updating webpack won't help

@sokra
Copy link
Member

sokra commented Mar 28, 2022

webpack/webpack#15574

@sannajammeh
Copy link
Contributor

Im getting [webpack.cache.PackFileCacheStrategy] Caching failed for pack: RangeError: Array buffer allocation failed after periods of either idle or a few hours of developing. Worst case the entire process crashes with Node being unable to garbage collect.

@vankop
Copy link

vankop commented Aug 2, 2022

this should be solved in webpack/webpack#15611

@enigma0Z
Copy link

enigma0Z commented Jan 18, 2023

I'm just working on implementing next.js in my project (coming from create-react-app) and I'm seeing this everywhere in my project.

Running latest next.js (13.x.x) and whatever version of webpack that pulls in.

Could this be why I see some components not receiving their dynamic styles from Material UI's dynamic in-code styles --

export default function MyComponent() {
  const theme = useTheme()
  const styles = (theme: Theme) => ({
    FooStyle: {
      backgroundColor: 'white' // normally dark
      color: 'black' // normally white, dark mode
    }
  })
  const classes = styles(theme)

  return (
    <Box sx={{classes.FooStyle}}>Test Test</Box>
  )
}

In my code this yields a white box with white text. It works with the create-react-app framework I'm coming from, for what its worth.

jenkinz added a commit to jenkinz/taxonomy that referenced this issue Mar 4, 2023
@timneutkens timneutkens added the linear: next Confirmed issue that is tracked by the Next.js team. label Jul 4, 2023
@PaisaDekho
Copy link

hey is this issue got fixed i guess not because I'm still seeing this same error in my next js 13.4.9 app

@vegandiet705
Copy link

vegandiet705 commented Jul 17, 2023

@PaisaDekho I also got this issue all of a sudden while developing my app, right after installing some packages related to authentication. Solved by killing the dev server, deleting the .next folder and launching the dev server again.

@haneenmahd
Copy link

In my case, removing the apprDir from experimental features in Next Config fixed this issue 👍🏼 !

@MakindeAhmed2110

This comment was marked as spam.

@Asish-AP
Copy link

@PaisaDekho I also got this issue all of a sudden while developing my app, right after installing some packages related to authentication. Solved by killing the dev server, deleting the .next folder and launching the dev server again.

Hey @vegandiet705 i tried removing the .next folder and then again building the project but was unable to solve the issue

luwes added a commit to luwes/next-video that referenced this issue Dec 19, 2023
heff pushed a commit to muxinc/next-video that referenced this issue Dec 19, 2023
* fix: loading next.config.mjs if needed
* fix: init output for esm next.config.mjs
* fix: webpack dynamic import warning
related vercel/next.js#33693
@aligajani
Copy link

@Asish-AP Any luck? Having same issue.

@RahulShilam
Copy link

@Asish-AP Any luck? Having same issue.

Delete Next Folder in your app and try re-running your app, it worked for me...

@aligajani
Copy link

aligajani commented Mar 3, 2024 via email

@samcx
Copy link
Member

samcx commented Apr 30, 2024

This is supported now so closing this!

@samcx samcx closed this as completed Apr 30, 2024
@samcx samcx removed the kind: bug label Apr 30, 2024
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
linear: next Confirmed issue that is tracked by the Next.js team. locked Webpack Related to Webpack with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.