Giter VIP home page Giter VIP logo

Comments (14)

andyperlitch avatar andyperlitch commented on May 30, 2024 8

FYI, this appears to be broken in 3.0.0-beta2. We downgraded to 2.0.1 and it worked.

from inject-loader.

thomasklein avatar thomasklein commented on May 30, 2024

+1

from inject-loader.

kpdecker avatar kpdecker commented on May 30, 2024

What version of babel is this?

It's working fine for me under this version:

├─┬ [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]

The code that is generated looks something like this:

var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };

var EventEmitter = injections["events"].EventEmitter;
var Reflux = _interopRequire(injections["reflux"]);
var AuthActions = _interopRequire(injections["actions/authentication"]);

from inject-loader.

plasticine avatar plasticine commented on May 30, 2024

I would like to actually add some test coverage around this and make sure it is working / ensure that it stay working.

from inject-loader.

tomatau avatar tomatau commented on May 30, 2024

babel: ^5.0.0

The 5.0 introduces many big improvements but changes many of it's internals since 4.x around the module system.

from inject-loader.

kpdecker avatar kpdecker commented on May 30, 2024

This works for me under 5.0, but I am running with #7 merged (which appears to have been released under inject-loader 2.0.0).

    function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
    var _reflux = (injections['reflux'] || __webpack_require__(116));
    var _reflux2 = _interopRequireDefault(_reflux);
...
        _reflux2['default']

My first guess, without seeing a repo case, is that the injection was missing, which causes the eventual .default reference to be undefined. I'm not seeing it locally as I have the failover from #7 in place. This is just a guess though.

@plasticine glad to try to PR some tests for this if I can make some time. It may be a few weeks, unfortunately.

from inject-loader.

kpdecker avatar kpdecker commented on May 30, 2024

I also had to do some hacks around the __esModule flag, which isn't really related to inject-loader persay, but we might be able to find a good utility or similar to help make that a bit more transparent.

from inject-loader.

nkbt avatar nkbt commented on May 30, 2024

For me it works well, see example in https://github.com/in-flux/component-router/blob/master/test/Store-test.js and other tests in the repo.

Though there seems to be an issue when module exports more then one thing. Injector simply returns empty object in that case.

See example https://github.com/chenglou/react-motion/blob/f43b9365c3552d38d144358101b1496c7f4c716a/test/Spring-test.js

Not sure if it is helpful. I wanted to debug it later, maybe get some positive results

from inject-loader.

nkbt avatar nkbt commented on May 30, 2024

Made a separate build:

/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

module.exports = function inject(injections) {
var module = {exports: {}};
//import React, {PropTypes} from 'react';
'use strict';

exports.__esModule = true;
exports.updateCurrValue = updateCurrValue;
exports.updateCurrVelocity = updateCurrVelocity;

// ....

exports.TransitionSpring = TransitionSpring;
return module.exports;
}

So module.exports is never filled. Only exports. But injector returns module.exports.

If module exports default, then everything works fine:

/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {

module.exports = function inject(injections) {
var module = {exports: {}};
'use strict';

exports.__esModule = true;
exports['default'] = noVelocity;

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _lodashIsplainobject = (injections['lodash.isplainobject'] || __webpack_require__(3));

var _lodashIsplainobject2 = _interopRequireDefault(_lodashIsplainobject);

function noVelocity(coll) {
  if (Array.isArray(coll)) {
    return coll.every(noVelocity);
  }
  if (_lodashIsplainobject2['default'](coll)) {
    return Object.keys(coll).every(function (key) {
      return key === 'config' ? true : noVelocity(coll[key]);
    });
  }
  return typeof coll === 'number' ? coll === 0 : true;
}

module.exports = exports['default'];
return module.exports;
}

from inject-loader.

rpominov avatar rpominov commented on May 30, 2024

Same issue here. When a module exports default and only default it works fine. But if it also exports something else, the result of injector(injections) is an empty object.

When I was trying to find the issue, I saw the same generated code as @nkbt posted. At the top it creates module variable, and returns module.exports at the bottom, but in the middle exports variable is used, which is an argument of upper function function(module, exports, __webpack_require__) {.

Seems like in case of importing default it works just by a coincidence.

Perhaps the code at the top of injector should be:

var module = {exports: {}};
var exports = module.exports;

from inject-loader.

rpominov avatar rpominov commented on May 30, 2024

Ah, I see it already fixed by #11. Cool, waiting for release and install from github in meantime 👍

from inject-loader.

plasticine avatar plasticine commented on May 30, 2024

@rpominov Hey there, yep—hopefully fixed in #11. I’m back at a computer as of tomorrow, so I’ll try and verify everything is A-OK and ship a release then. :)

from inject-loader.

rpominov avatar rpominov commented on May 30, 2024

Great, thank you! Btw, I just installed from github and it works fine for us 👌

from inject-loader.

plasticine avatar plasticine commented on May 30, 2024

OK, I’ve published 2.0.1, which should hopefully fix the issues with Babel generated code. Please have a look and open a new issue if there are dramas. ❤️

from inject-loader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.