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

Support resolving modules #15

Closed m10 closed 2 years ago

m10 commented 2 years ago

Requiring any modules defined in webpack configuration under resolve.modules does not seem to work currently. This also affects any npm modules under node_modules

Pug: - const classnames = require('classnames');

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.
  PugLoaderException:
  [pug-loader] the file 'classnames' can't be resolved in the pug template:
  /path/to/project/pug/file.pug
  Error: Can't resolve 'classnames' in '/path/to/project/pug/'
      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:217:21
      at Object.compile (/path/to/project/node_modules/@webdiscus/pug-loader/src/index.js:168:5)
      at Object.module.exports (/path/to/project/node_modules/@webdiscus/pug-loader/src/index.js:216:11)
  ModuleBuildError: Module build failed (from ./node_modules/@webdiscus/pug-loader/src/index.js): 
webdiscus commented 2 years ago

@m10 Thank you for the report.

Resolving of modules under node_modules was intentionally disabled to increase performance when used huge amount of required resources (e.g. images, icons) and because using of a npm module directly in pug template is very very rare case.

Now I activated revolving under node_modules too.

Fixed version is 2.1.1.