Comments (14)
FYI, this appears to be broken in 3.0.0-beta2
. We downgraded to 2.0.1
and it worked.
from inject-loader.
+1
from inject-loader.
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.
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.
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.
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.
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.
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.
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.
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.
Ah, I see it already fixed by #11. Cool, waiting for release and install from github in meantime 👍
from inject-loader.
@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.
Great, thank you! Btw, I just installed from github and it works fine for us 👌
from inject-loader.
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)
- Thanks HOT 1
- Not working for me HOT 3
- Webpack + coffeescript + inject-loader HOT 2
- Cannot find module HOT 18
- Any chance of transitive dependencies ? HOT 2
- Webpack 3 compatibility HOT 2
- Regression: When injecting a falsey export, it shouldn't fall back to real module HOT 3
- babelrc config not used HOT 1
- Not working with React Native packager? HOT 1
- Support code-coverage instrumentation HOT 2
- Add webpack v4 to peerDependencies HOT 2
- Work with Jest HOT 3
- Mocking out the 'request-promise' library HOT 1
- Add more tests HOT 1
- Calling require() with dynamically formed paths leads to runtime issue with webpack
- Cannot mock default and named exports together HOT 1
- Add support for Babel 7 HOT 8
- Nested dependencies? HOT 1
- TS-support
- Webpack version 5.x support? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inject-loader.