Registry /
devops / yyl-sugar-webpack-plugin
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
YylSugarWebpackPlugin
✓ const YylSugarWebpackPlugin = require('yyl-sugar-webpack-plugin')
✗ import YylSugarWebpackPlugin from 'yyl-sugar-webpack-plugin'
Package uses CommonJS; require is required for correct import; no default ESM export provided.
getHooks
✓ import { getHooks } from 'yyl-sugar-webpack-plugin'
✗ const { getHooks } = require('yyl-sugar-webpack-plugin')
Actually, getHooks is accessed via the imported plugin class (IPlugin.getHooks(compilation)), not a separate import. Common mistake: trying to import getHooks directly.
getName
✓ YylSugarWebpackPlugin.getName()
✗ new YylSugarWebpackPlugin().getName()
getName is a static method on the class, not an instance method.
Shows basic usage of YylSugarWebpackPlugin as a webpack plugin with CJS require and an example of hooking into beforeSugar.
const YylSugarWebpackPlugin = require('yyl-sugar-webpack-plugin');
const path = require('path');
const webpackConfig = {
plugins: [
new YylSugarWebpackPlugin({ basePath: __dirname })
]
};
module.exports = webpackConfig;
// To extend with hooks:
const PLUGIN_NAME = 'ExtPlugin';
class ExtPlugin {
apply(compiler) {
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
YylSugarWebpackPlugin.getHooks(compilation).beforeSugar.tapAsync(PLUGIN_NAME, (obj, done) => {
console.log('beforeSugar', obj);
done(null, obj);
});
});
}
}
Errors
Common errors & fixes
TypeError: YylSugarWebpackPlugin is not a constructor
ESM import used instead of require; package only provides CJS export.
fixReplace import with const YylSugarWebpackPlugin = require('yyl-sugar-webpack-plugin') Error: Cannot find module 'yyl-sugar-webpack-plugin'
Package not installed or incorrect path; also occurs when using ESM in environment that expects module resolution.
fixRun npm install yyl-sugar-webpack-plugin and use require()
TypeError: Cannot read properties of undefined (reading 'beforeSugar')
getHooks called without compilation object or before hooks are set up.
fixEnsure getHooks is called inside a compilation hook (e.g., compiler.hooks.compilation.tap) and that compilation is not null.
Audit
Dependencies
webpackrequiredPeer dependency required for plugin functionality; must be >=5.0.0