plasticine / inject-loader

๐Ÿ’‰๐Ÿ“ฆ A Webpack loader for injecting code into modules via their dependencies.
https://www.npmjs.com/package/inject-loader
MIT License
484 stars 47 forks source link

Loader didn't return a function error [3.0.0-beta1] #18

Closed Aaronius closed 8 years ago

Aaronius commented 8 years ago

When I try to upgrade from 2.x to 3.0.0-beta1 I start getting the following errors:

ERROR in Loader /Users/aahardy/dev/extension-support-testrunner/node_modules/inject-loader/lib/index.js didn't return a function
 @ ./src/lib/actions/__tests__/setCustomerIds.test.js 4:29-64

ERROR in Loader /Users/aahardy/dev/extension-support-testrunner/node_modules/inject-loader/lib/index.js didn't return a function
 @ ./src/lib/sharedModules/__tests__/mcidInstance.test.js 4:32-65

I'm guessing it has to do with the es6 modules in 3.x or something.

plasticine commented 8 years ago

@aaronius thanks will have a look ๐Ÿ‘๐Ÿผ

oviava commented 8 years ago
function inject(source) {
  this.cacheable && this.cacheable();
  return 'module.exports = ' + createInjectorFunction(this, source);
}

// Object.defineProperty(exports, "__esModule", {
//   value: true
// });
// exports.default = inject;

module.exports = inject;

a bit of hit & miss as I don't understand webpack loader system that well but this fixed it for me

lvthanh101 commented 8 years ago

hi @plasticine, do you have plan to fix this bug?

plasticine commented 8 years ago

@lvthanh101 Yep, just havenโ€™t had time. Hopefully soon.

zincli commented 7 years ago

hey man, I guess you made a mistake on return value. like @oviava said

function inject(source) {
  this.cacheable && this.cacheable();
  return 'module.exports = ' + createInjectorFunction(this, source);
}

the return value should be a module, it should export some thing. so module.exports here should not omit.

19 got everything broken.

zincli commented 7 years ago

https://github.com/plasticine/inject-loader/blob/master/lib/index.js#L107 here's the problem

plasticine commented 7 years ago

Please check out 3.0.0-beta3 which should fix this issue and also introduces support for webpack2.