loaderUtil.getOptions returns null: “this” object is empty in loader function

Do you want to request a feature or report a bug?

What is the current behavior?
I’m trying to create a custom loader in order to generate the manifest.json file for a chrome extension, and the “options” object via loaderUtils.getOptions() is null because this is an empty object…

If the current behavior is a bug, please provide the steps to reproduce.
The relevant code…


const loaderUtils = require('loader-utils');

module.exports = (source) => {
  const options = loaderUtils.getOptions(this);
  const env = options.env;
  let APP_DOMAIN = env === 'production' ? 'production_domain' : 'http://localhost:3000';
  let icons = env === 'production' ? ({
    "16": "icon16.png",
    "48": "icon48.png",
    "128": "icon128.png"
  }) : ({ "128": "icon-dev128.png" });

  let manifest_template = JSON.parse(source);
  manifest_template.icons = icons;

  let indentation = this.minimize ? null : 2
  return JSON.stringify(manifest_template, null, indentation) + '\n'


  test: /manifest\.json$/,
  use: {
    loader: path.resolve('src/loaders/manifest-loader.js'),
    options: {
      env: `${env.NODE_ENV}`

What is the expected behavior?
That this not be empty, and that loaderUtils.getOptions returns the options specified in the webpack.config.js file.

Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.

node: v8.1.0
"webpack": "^4.6.0",
"webpack-cli": "^2.0.15",
"webpack-dev-server": "^3.1.3",
"webpack-merge": "^4.1.2"

Author: Fantashit

1 thought on “loaderUtil.getOptions returns null: “this” object is empty in loader function

Comments are closed.