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

Cannot read properties of undefined (reading 'sync') in @webdiscus\pug-loader\src\Resolver.js #22

Closed itsBen closed 1 year ago

itsBen commented 1 year ago

Hi,

I am facing following issue:

ERROR in ./src/views/pages/index.pug
Module build failed (from ./node_modules/@webdiscus/pug-loader/src/index.js):
TypeError: Cannot read properties of undefined (reading 'sync')
    at Resolver.init (C:\projects\code\pug-loader-issue\node_modules\@webdiscus\pug-loader\src\Resolver.js:33:47)
    at Object.compile (C:\projects\code\pug-loader-issue\node_modules\@webdiscus\pug-loader\src\index.js:269:14)
    at Object.module.exports (C:\projects\code\pug-loader-issue\node_modules\@webdiscus\pug-loader\src\index.js:334:11)

Full output

PS C:\projects\code\pug-loader-issue> npm run start

> pug-loader-issue@1.0.0 start
> cross-env NODE_ENV=development webpack serve --config config/webpack.dev.js

<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:8082/
<i> [webpack-dev-server] On Your Network (IPv4): 
<i> [webpack-dev-server] On Your Network (IPv6): 
<i> [webpack-dev-server] Content not from webpack is served from 'C:\projects\code\pug-loader-issue\public' directory
PublicPath: auto
asset index.html 219 KiB [emitted] (name: index)
Entrypoint index 219 KiB = index.html
chunk (runtime: index) index.html (index) 27.3 KiB (runtime) 160 KiB (javascript) [entry] [rendered]
runtime modules 27.3 KiB 12 modules
modules by path ./node_modules/ 160 KiB
  modules by path ./node_modules/webpack-dev-server/client/ 55.8 KiB 12 modules
  modules by path ./node_modules/webpack/hot/*.js 4.3 KiB
    ./node_modules/webpack/hot/dev-server.js 1.59 KiB [built] [code generated]
    ./node_modules/webpack/hot/log.js 1.34 KiB [built] [code generated]
    + 2 modules
  modules by path ./node_modules/html-entities/lib/*.js 81.3 KiB
    ./node_modules/html-entities/lib/index.js 7.74 KiB [built] [code generated]
    ./node_modules/html-entities/lib/named-references.js 72.7 KiB [built] [code generated]
    + 2 modules
  ./node_modules/ansi-html-community/index.js 4.16 KiB [built] [code generated]
  ./node_modules/events/events.js 14.5 KiB [built] [code generated]
./src/views/pages/index.pug 39 bytes [built] [code generated] [1 error]

LOG from webpack.Compilation
    23 modules hashed, 0 from cache (1 variants per module in average)
    100% code generated (23 generated, 0 from cache)
    100% code generated (12 generated, 0 from cache)
+ 25 hidden lines

LOG from webpack.ResolverCachePlugin
    94% really resolved (29 real resolves with 0 cached but invalid, 2 cached valid, 0 concurrent)

LOG from webpack.FlagDependencyExportsPlugin
    61% of exports of modules have been determined (9 no declared exports, 14 not cached, 0 flagged uncacheable, 0 from cache, 0 from mem cache, 0 additional calculations due to dependencies)
+ 3 hidden lines

LOG from webpack.buildChunkGraph
    48 queue items processed (23 blocks)
    0 chunk groups connected
    0 chunk groups processed for merging (0 module sets, 0 forked, 0 + 0 modules forked, 0 + 0 modules merged into fork, 0 resulting modules)
    0 chunk group info updated (0 already connected chunk groups reconnected)
+ 5 hidden lines

LOG from webpack.FileSystemInfo
    51 new snapshots created
    0% root snapshot uncached (0 / 2)
    0% children snapshot uncached (0 / 0)
    0 entries tested
    File info in cache: 14 timestamps 0 hashes 0 timestamp hash combinations
    File timestamp snapshot optimization: 90% (140/156) entries shared via 2 shared snapshots (26 times referenced)
    Directory info in cache: 0 timestamps 0 hashes 0 timestamp hash combinations
    Missing items snapshot optimization: 0% (0/3) entries shared via 0 shared snapshots (0 times referenced)
    Managed items info in cache: 20 items
    Managed items snapshot optimization: 21% (16/77) entries shared via 2 shared snapshots (2 times referenced)
    Managed files snapshot optimization: 44% (75/172) entries shared via 3 shared snapshots (22 times referenced)
    Managed missing snapshot optimization: 16% (16/98) entries shared via 2 shared snapshots (3 times referenced)

ERROR in ./src/views/pages/index.pug
Module build failed (from ./node_modules/@webdiscus/pug-loader/src/index.js):
TypeError: Cannot read properties of undefined (reading 'sync')
    at Resolver.init (C:\projects\code\pug-loader-issue\node_modules\@webdiscus\pug-loader\src\Resolver.js:33:47)
    at Object.compile (C:\projects\code\pug-loader-issue\node_modules\@webdiscus\pug-loader\src\index.js:269:14)
    at Object.module.exports (C:\projects\code\pug-loader-issue\node_modules\@webdiscus\pug-loader\src\index.js:334:11)
ModuleBuildError: Module build failed (from ./node_modules/@webdiscus/pug-loader/src/index.js):
TypeError: Cannot read properties of undefined (reading 'sync')
    at Resolver.init (C:\projects\code\pug-loader-issue\node_modules\@webdiscus\pug-loader\src\Resolver.js:33:47)
    at Object.compile (C:\projects\code\pug-loader-issue\node_modules\@webdiscus\pug-loader\src\index.js:269:14)
    at Object.module.exports (C:\projects\code\pug-loader-issue\node_modules\@webdiscus\pug-loader\src\index.js:334:11)
    at processResult (C:\projects\code\pug-loader-issue\node_modules\webpack\lib\NormalModule.js:758:19)
    at C:\projects\code\pug-loader-issue\node_modules\webpack\lib\NormalModule.js:860:5
    at C:\projects\code\pug-loader-issue\node_modules\loader-runner\lib\LoaderRunner.js:400:11
    at C:\projects\code\pug-loader-issue\node_modules\loader-runner\lib\LoaderRunner.js:252:18
    at runSyncOrAsync (C:\projects\code\pug-loader-issue\node_modules\loader-runner\lib\LoaderRunner.js:156:3)
    at iterateNormalLoaders (C:\projects\code\pug-loader-issue\node_modules\loader-runner\lib\LoaderRunner.js:251:2)
    at C:\projects\code\pug-loader-issue\node_modules\loader-runner\lib\LoaderRunner.js:224:4
    at C:\projects\code\pug-loader-issue\node_modules\webpack\lib\NormalModule.js:834:15
    at Array.eval (eval at create (C:\projects\code\pug-loader-issue\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:12:1)
    at runCallbacks (C:\projects\code\pug-loader-issue\node_modules\webpack\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:27:15)

2022-09-10 23:03:20: webpack 5.74.0 compiled with 1 error in 4126 ms (47ef832b0d2f0acfd69a)

webpack.dev.config.js

/* eslint-disable */
const {
  CleanWebpackPlugin,
} = require('clean-webpack-plugin')
const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
const PugPlugin = require('pug-plugin')

const paths = require('./paths')

const loaders = require('../webpack/loaders');
/* eslint-enable */

module.exports = {

  mode: 'development',
  devtool: 'source-map',

  // Where webpack outputs the assets and bundles
  output: {
    path: paths.dist,
    publicPath: 'auto',

    // output filename of scripts
    filename: 'assets/js/[name].[contenthash:8].js',
    chunkFilename: 'assets/js/[id].[contenthash:8].js',
    clean: true,
  },

  resolve: {
    // aliases used in sources
    alias: {
      Root: paths.root,
      Src: paths.src.root,
      Views: paths.src.views,
      Images: paths.src.images,
      Fonts: paths.src.fonts,
      Styles: paths.src.styles,
      Scripts: paths.src.scripts,
    },
    preferRelative: true,

    // resolve omitted extensions
    extensions: ['.js'],
  },

  // Where webpack looks to start building the bundle
  entry: {
    index: './src/views/pages/index.pug',
    // 404: './src/views/pages/404.pug',
  },

  // Determine how modules within the project are treated
  module: {
    rules: [
      // pug
      loaders.pugLoader(),

      // styles
      loaders.sassLoader(),

      // images
      loaders.imageLoader(),

      // inline images by size (to force inline use the `?inline` query)
      // ...loaders.inlineImageLoader(2 * 1024),

      // fonts
      loaders.fontLoader(),

      // generates filename including last directory name
      // to group fonts by name

      // eslint-disable-next-line max-len
      // (pathData) => `assets/fonts/${path.basename(path.dirname(pathData.filename))}/[name][ext][query]`
    ],
  },

  // Customize the webpack build process
  plugins: [

    // Removes/cleans build folders and unused assets when rebuilding
    new CleanWebpackPlugin(),

    new PugPlugin({
      verbose: true, // output information about the process to console
      pretty: true, // output formatted HTML
      // extract CSS from style source files specified directly in Pug
      extractCss: {
        // output filename of styles
        filename: 'assets/css/[name].[contenthash:8].css',
      },
    }),
  ],

  performance: {
    hints: 'warning',
    // in development mode the size of entrypoint
    // and assets is bigger than in production
    maxEntrypointSize: 15000 * 1024,
    maxAssetSize: 4000 * 1024,
  },

  stats: {
    colors: true,
    // see https://webpack.js.org/configuration/stats/#stats-presets
    // preset: 'minimal',
    // enable @debug output

    env: true,
    // include value of --env in the output
    outputPath: true,
    // include absolute output path in the output
    publicPath: true,
    // include public path in the output

    assets: true,
    // show list of assets in output

    entrypoints: true,
    // show entrypoints list
    chunkGroups: true,
    // show named chunk group list

    chunks: true,
    // show list of chunks in output

    modules: true,
    // show list of modules in output

    children: true,
    // show stats for child compilations

    logging: true,
    // show logging in output
    loggingDebug: ['sass-loader'],
    // show debug type logging for some loggers
    loggingTrace: true,
    // show stack traces for warnings and errors in logging output

    warnings: true,
    // show warnings

    errors: true,
    // show errors
    errorDetails: true,
    // show details for errors
    errorStack: true,
    // show internal stack trace for errors
    moduleTrace: true,
    // show module trace for errors
    // (why was causing module referenced)

    builtAt: true,
    // show timestamp in summary
    errorsCount: true,
    // show errors count in summary
    warningsCount: true,
    // show warnings count in summary
    timings: true,
    // show build timing in summary
    version: true,
    // show webpack version in summary
    hash: true,
    // show build hash in summary
  },
}

Steps to reproduce

  1. clone https://github.com/itsBen/pug-loader-issue
  2. run npm run start

System

OS Name Microsoft Windows 10 Pro Version 10.0.19044 Build 19044

webdiscus commented 1 year ago

Hallo Ben, danke für die BUG-Meldung. Ich kümmere mich darum.

Viele Grüße, Dimitri

itsBen commented 1 year ago

Hi Dimitri,

danke für den PR. Wie von dir beschrieben, lag es daran, dass eslint-import-resolver-webpack eine veraltete Version von enhanced-resolve nutzt.

Viele Grüße Ben