webdiscus / pug-loader

Pug loader for Webpack renders pug to HTML or template function
https://webdiscus.github.io/pug-loader/pug-filters
ISC License
72 stars 5 forks source link

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

Closed XenoBino closed 2 years ago

XenoBino commented 2 years ago

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.

webdiscus commented 2 years ago

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 commented 2 years ago

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.

https://github.com/Spence-S/simple-pug-loader/issues/10

webdiscus commented 2 years ago

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

m10 commented 2 years ago

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..

https://github.com/webdiscus/pug-loader/blob/b43003272296f8802afb695f02dc059323aa837f/src/index.js#L167

webdiscus commented 2 years ago

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..

https://github.com/webdiscus/pug-loader/blob/b43003272296f8802afb695f02dc059323aa837f/src/index.js#L167

Could you please show your short snippets of Pug:

webdiscus commented 2 years ago

@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
  2. dependency.pug

    
    h1 Dependency

//- This line is invalid and generates an error

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

webdiscus commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

@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.