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

Compile error on bad JS Syntax is confusing #17

Closed m10 closed 2 years ago

m10 commented 2 years ago

The error message that is output when attempting to compile pug templates with a javascript syntax error is confusing.

Example:

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

//- This line is invalid and generates an error

ERROR in Error: Child compilation failed: Module build failed (from ./node_modules/@webdiscus/pug-loader/src/index.js): NonErrorEmittedError: (Emitted value instead of an instance of Error) [pug-loader] Pug compilation failed. Error: Error parsing body of the with expression at processResult (/path/to/project/node_modules/webpack/lib/NormalModule.js:755:12) at /path/to/project/node_modules/webpack/lib/NormalModule.js:860:5 at /path/to/project/node_modules/loader-runner/lib/LoaderRunner.js:400:11 at /path/to/project/node_modules/loader-runner/lib/LoaderRunner.js:252:18 at context.callback (/path/to/project/node_modules/loader-runner/lib/LoaderRunner.js:124:13) at /path/to/project/node_modules/@webdiscus/pug-loader/src/index.js:284:21 at Object.compile (/path/to/project/node_modules/@webdiscus/pug-loader/src/index.js:244:5) at Object.module.exports (/path/to/project/node_modules/@webdiscus/pug-loader/src/index.js:283:11) ModuleBuildError: Module build failed (from ./node_modules/@webdiscus/pug-loader/src/index.js): NonErrorEmittedError: (Emitted value instead of an instance of Error) [pug-loader] Pug compilation failed. Error: Error parsing body of the with expression at processResult (/path/to/project/node_modules/webpack/lib/NormalModule.js:755:12) at /path/to/project/node_modules/webpack/lib/NormalModule.js:860:5 at /path/to/project/node_modules/loader-runner/lib/LoaderRunner.js:400:11 at /path/to/project/node_modules/loader-runner/lib/LoaderRunner.js:252:18 at context.callback (/path/to/project/node_modules/loader-runner/lib/LoaderRunner.js:124:13) at /path/to/project/node_modules/@webdiscus/pug-loader/src/index.js:284:21 at Object.compile (/path/to/project/node_modules/@webdiscus/pug-loader/src/index.js:244:5) at Object.module.exports (/path/to/project/node_modules/@webdiscus/pug-loader/src/index.js:283:11) at processResult (/path/to/project/node_modules/webpack/lib/NormalModule.js:758:19) at /path/to/project/node_modules/webpack/lib/NormalModule.js:860:5 at /path/to/project/node_modules/loader-runner/lib/LoaderRunner.js:400:11 at /path/to/project/node_modules/loader-runner/lib/LoaderRunner.js:252:18 at context.callback (/path/to/project/node_modules/loader-runner/lib/LoaderRunner.js:124:13) at /path/to/project/node_modules/@webdiscus/pug-loader/src/index.js:284:21 at Object.compile (/path/to/project/node_modules/@webdiscus/pug-loader/src/index.js:244:5) at Object.module.exports (/path/to/project/node_modules/@webdiscus/pug-loader/src/index.js:283:11) at LOADER_EXECUTION (/path/to/project/node_modules/loader-runner/lib/LoaderRunner.js:132:14) at runSyncOrAsync (/path/to/project/node_modules/loader-runner/lib/LoaderRunner.js:133:4)

webpack compiled with 2 errors

webdiscus commented 2 years ago

@m10

This is Pug compiler error. You can create the issue directly by pugjs/pug.

m10 commented 2 years ago

@webdiscus that's a pity..

anyway i found an issue that's already been filed in 2020 https://github.com/pugjs/pug/issues/3277

webdiscus commented 2 years ago

@m10

Workaround of parser error

Create a JS module: regexp.js

module.exports = /.+/$

then in Pug you can use this JS module index.pug


- const regexp = require('./regexp.js');