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

[Bug] Pug error in dependency requires restart of webpack #14

Closed
XenoBino opened this issue May 10, 2022 · 9 comments
Closed

[Bug] Pug error in dependency requires restart of webpack #14

XenoBino opened this issue May 10, 2022 · 9 comments
Labels
bug Something isn't working
Milestone

Comments

@XenoBino
Copy link

XenoBino commented May 10, 2022

I am facing a non reproducible issue where:

  [pug-loader] Pug compilation failed.
  Error: Error parsing body of the with expression

Doesn't go even if I comment the whole file. It requires me to restart the webpack dev server instance. My build is CPU intensive. It takes about half a minute to have something on the screen and caching is not working properly. I have to wait half a minute every time a pug error occurs. And pug errors are extremely unreadable. Making it even harder to fix the pug error.

@XenoBino XenoBino changed the title Pug error requires restart of webpack [Bug] Pug error requires restart of webpack May 10, 2022
@webdiscus
Copy link
Owner

webdiscus commented May 10, 2022

Hello @XenoBino,

thank You for the report.

  1. I need to see your webpack.config.js and pug template.
  2. Are you using the self option of the pug loader? Is it enabled?
  3. Does the error occur in build mode: webpack --mode=production, not with serv?

Seems this is Pug compiler error, not pug-loader.
Something is in your Pug template wrong.

@m10
Copy link

m10 commented May 11, 2022

i get that error too when there is e.g. a syntax error in a javascript snippet in the pug template.
I agree that the error message is most unhelpful.

the overall problem with error handling ("requires restart") seems to be that the loader / pug can't resolve the dependencies anymore and thus webpack does not watch the files anymore. Only the entrypoint is still being watched, saving that one will trigger a rebuild. One has to know that though.

Other loaders have / had this problem too. E.g. simlpe-pug-loader adds at least the file where the error happened, even if not ideal it does help. A mechanism to remember the dependencies and keep watching them on error would be ideal though.

spence-s/simple-pug-loader#10

@webdiscus
Copy link
Owner

@m10 Thanks for explaining the problem. This helps me to start researching the problem.

@m10
Copy link

m10 commented May 11, 2022

I checked the source and @webdiscus/pug-loader does in fact add the error file as dependency. For some reason this does not seem to work for this kind of error. Maybe pug does not return any filename in this case..

if (error.filename) loaderContext.addDependency(path.normalize(error.filename));

@webdiscus
Copy link
Owner

I checked the source and @webdiscus/pug-loader does in fact add the error file as dependency. For some reason this does not seem to work for this kind of error. Maybe pug does not return any filename in this case..

if (error.filename) loaderContext.addDependency(path.normalize(error.filename));

Could you please show your short snippets of Pug:

  • the snippet works correctly
  • the same snippet contained a Pug error that is causing this issue

@webdiscus
Copy link
Owner

webdiscus commented May 18, 2022

@m10 @XenoBino
I can reproduce the error Error parsing body of the with expression with following invalid code:

- const str = /.+/$

Reproduce

We need two Pug files:

  1. index.pug
h1 Index
include dependency
  1. dependency.pug
h1 Dependency

//- This line is invalid and generates an error
- const str = /.+/$

When an invalid code is in included dependency.pug file then appear not recoverable error and webpack must be restarted.

@webdiscus webdiscus modified the milestones: analyse, in development May 18, 2022
@webdiscus webdiscus changed the title [Bug] Pug error requires restart of webpack [Bug] Pug error in dependency requires restart of webpack May 18, 2022
@webdiscus webdiscus modified the milestones: in development, testing May 18, 2022
@webdiscus webdiscus modified the milestones: testing, done May 18, 2022
@webdiscus
Copy link
Owner

@XenoBino @m10

the issue is fixed in version 2.2.1.
Do you can please test it and give a feedback whether the problem is solved?

@m10
Copy link

m10 commented May 25, 2022

@webdiscus i can confirm that the newest version 2.3.0 recovers correctly from JS syntax errors.

The error message ist still confusing though. Should that be tracked in a separate issue?

@webdiscus webdiscus added the bug Something isn't working label May 25, 2022
@webdiscus
Copy link
Owner

webdiscus commented May 25, 2022

@webdiscus i can confirm that the newest version 2.3.0 recovers correctly from JS syntax errors.

The error message ist still confusing though. Should that be tracked in a separate issue?

Yes, please new issue/enhancement create in a separate issue, inc. your error message completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants