Closed m10 closed 2 years ago
@m10
This is Pug compiler error. You can create the issue directly by pugjs/pug.
@webdiscus that's a pity..
anyway i found an issue that's already been filed in 2020 https://github.com/pugjs/pug/issues/3277
@m10
Create a JS module: regexp.js
module.exports = /.+/$
then in Pug you can use this JS module index.pug
- const regexp = require('./regexp.js');
The error message that is output when attempting to compile pug templates with a javascript syntax error is confusing.
Example:
//- This line is invalid and generates an error
const str = /.+/$
ERROR in ./src/index.pug (./node_modules/html-webpack-plugin/lib/loader.js!./src/index.pug) 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)
Child HtmlWebpackCompiler compiled with 1 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)
NormalModule.js:755 processResult [frontend-webpack]/[webpack]/lib/NormalModule.js:755:12
NormalModule.js:860 [frontend-webpack]/[webpack]/lib/NormalModule.js:860:5
LoaderRunner.js:400 [frontend-webpack]/[loader-runner]/lib/LoaderRunner.js:400:11
LoaderRunner.js:252 [frontend-webpack]/[loader-runner]/lib/LoaderRunner.js:252:18
LoaderRunner.js:124 context.callback [frontend-webpack]/[loader-runner]/lib/LoaderRunner.js:124:13
index.js:284 [frontend-webpack]/[@webdiscus]/pug-loader/src/index.js:284:21
index.js:244 Object.compile [frontend-webpack]/[@webdiscus]/pug-loader/src/index.js:244:5
index.js:283 Object.module.exports [frontend-webpack]/[@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
NormalModule.js:755 processResult [frontend-webpack]/[webpack]/lib/NormalModule.js:755:12
NormalModule.js:860 [frontend-webpack]/[webpack]/lib/NormalModule.js:860:5
LoaderRunner.js:400 [frontend-webpack]/[loader-runner]/lib/LoaderRunner.js:400:11
LoaderRunner.js:252 [frontend-webpack]/[loader-runner]/lib/LoaderRunner.js:252:18
LoaderRunner.js:124 context.callback [frontend-webpack]/[loader-runner]/lib/LoaderRunner.js:124:13
index.js:284 [frontend-webpack]/[@webdiscus]/pug-loader/src/index.js:284:21
index.js:244 Object.compile [frontend-webpack]/[@webdiscus]/pug-loader/src/index.js:244:5
index.js:283 Object.module.exports [frontend-webpack]/[@webdiscus]/pug-loader/src/index.js:283:11
NormalModule.js:758 processResult [frontend-webpack]/[webpack]/lib/NormalModule.js:758:19
NormalModule.js:860 [frontend-webpack]/[webpack]/lib/NormalModule.js:860:5
LoaderRunner.js:400 [frontend-webpack]/[loader-runner]/lib/LoaderRunner.js:400:11
LoaderRunner.js:252 [frontend-webpack]/[loader-runner]/lib/LoaderRunner.js:252:18
LoaderRunner.js:124 context.callback [frontend-webpack]/[loader-runner]/lib/LoaderRunner.js:124:13
index.js:284 [frontend-webpack]/[@webdiscus]/pug-loader/src/index.js:284:21
index.js:244 Object.compile [frontend-webpack]/[@webdiscus]/pug-loader/src/index.js:244:5
index.js:283 Object.module.exports [frontend-webpack]/[@webdiscus]/pug-loader/src/index.js:283:11
LoaderRunner.js:132 LOADER_EXECUTION [frontend-webpack]/[loader-runner]/lib/LoaderRunner.js:132:14
LoaderRunner.js:133 runSyncOrAsync [frontend-webpack]/[loader-runner]/lib/LoaderRunner.js:133:4
child-compiler.js:169 [frontend-webpack]/[html-webpack-plugin]/lib/child-compiler.js:169:18
Compiler.js:551 finalCallback [frontend-webpack]/[webpack]/lib/Compiler.js:551:5
Compiler.js:577 [frontend-webpack]/[webpack]/lib/Compiler.js:577:11
Compiler.js:1196 [frontend-webpack]/[webpack]/lib/Compiler.js:1196:17
Hook.js:18 Hook.CALL_ASYNC_DELEGATE [as _callAsync] [frontend-webpack]/[tapable]/lib/Hook.js:18:14
Compiler.js:1192 [frontend-webpack]/[webpack]/lib/Compiler.js:1192:33
Compilation.js:2787 finalCallback [frontend-webpack]/[webpack]/lib/Compilation.js:2787:11
Compilation.js:3092 [frontend-webpack]/[webpack]/lib/Compilation.js:3092:11
webpack compiled with 2 errors