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

Runtime error after switching between dev-server and watch mode when using filesystem cache #1028

Open
Raykeen opened this issue Apr 10, 2023 · 3 comments

Comments

@Raykeen
Copy link

Raykeen commented Apr 10, 2023

Bug report

Using config with filesystem cache and mini-css-extract-plugin after switching from building project with dev-server to build with --watch I get runtime error Uncaught TypeError: Cannot read properties of undefined (reading 'dispose') ... .
I'm not shure if it's bug in plugin or webpack.

Actual Behavior

After build completes I open builded page and get runtime error:
Uncaught TypeError: Cannot read properties of undefined (reading 'dispose') ...
The code of main js entrypoint doesn't run.

Expected Behavior

No error and main js entrypoint runs.

How Do We Reproduce?

https://github.com/Raykeen/webpack-dev-watch-switch-hmr-issue

@alexander-akait
Copy link
Member

alexander-akait commented Apr 10, 2023

Yeah, I will add protection to this, but you need to fix your configuration for better caching, because dev and watch are different, you need to say webpack invalidate cache:

cache: {
        type: "filesystem",
        version: JSON.stringify({
            serve: process.env.WEBPACK_SERVE
        }),
        buildDependencies: {
            config: [__filename],
        }
    },

i.e. you invalidate cache between serve and watch, because when you run serve you have hot content

@Raykeen
Copy link
Author

Raykeen commented Apr 11, 2023

Yeah, I will add protection to this, but you need to fix your configuration for better caching, because dev and watch are different, you need to say webpack invalidate cache:

cache: {
        type: "filesystem",
        version: JSON.stringify({
            serve: process.env.WEBPACK_SERVE
        }),
        buildDependencies: {
            config: [__filename],
        }
    },

i.e. you invalidate cache between serve and watch, because when you run serve you have hot content

This fix works, thanks!

We often use both serve and watch, so more efficient solution for us is changing a name of cache like this.

cache: {
    name: `${name}-${inProduction ? "production" : "development"}${isDevServer ? "-hmr" : "" }`,
    ...
}

It would be better if this was the default behavior of webpack cache, but this is a webpack issue.

@alexander-akait
Copy link
Member

Yeah, we will consider it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants