webpack: that myloader run this.callback is undefined in myloader.js

Do you want to request a feature or report a bug? I think it’s bug

What is the current behavior? I want to develop a loader , but I can’t invoke callback of loader API .

If the current behavior is a bug, please provide the steps to reproduce. this is myloader.js

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

/*
  1、返回一个字符串
  2、source 是一个对象
*/
module.exports = function(source) {
  console.log('-------------------------hLoader-start----------------------------->');
  console.log('source', source);
  // console.log('this-------------------------->',this); // this of node
  console.log("callback------------->",this.callback); // undefined
  console.log('-------------------------hLoader-end----------------------------->');
  return "sdfjslkdjfljsdlfjlsdfj";
};

What is the expected behavior?

If this is a feature request, what is motivation or use case for changing the behavior?

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

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

sorry , my network is delay

I guess the require at the top is the problem this points to the node global object then. webpack (loader-runner) needs to require the loader and bind() the Loader API