enhanced-require
enhanced-require copied to clipboard
Node fibers throw an error when used with enhanced require
Error: Cannot resolve file or directory C:\app\node_modules\fibers\bin\win32-ia32-v8-3.14\fibers in C:\app\node_modules\fibers
Starts in index.js
GLOBAL.__webpack_public_path__ = '';
var options = require('../../webpack.config');
options.recursive = true;
var myRequire = require('enhanced-require')(module, options);
var boot = myRequire('server/boot');
boot.js:
var Fiber = require('fibers');
function sleep(ms) {
var fiber = Fiber.current;
setTimeout(function() {
fiber.run();
}, ms);
Fiber.yield();
}
Fiber(function() {
console.log('wait... ' + new Date);
sleep(1000);
console.log('ok... ' + new Date);
}).run();
console.log('back in main');
Which is the default fiber example.
In pure node js works fine, with enhanced require I get this error.
They seem to require a binary file:
var fs = require('fs'), path = require('path');
// Seed random numbers [gh-82]
Math.random();
// Look for binary for this platform
var v8 = 'v8-'+ /[0-9]+\.[0-9]+/.exec(process.versions.v8)[0];
var modPath = path.join(__dirname, 'bin', process.platform+ '-'+ process.arch+ '-'+ v8, 'fibers');
try {
fs.statSync(modPath+ '.node');
} catch (ex) {
// No binary!
throw new Error('`'+ modPath+ '.node` is missing. Try reinstalling `node-fibers`?');
}
// Pull in fibers implementation
module.exports = require(modPath).Fiber;
modPath is a string to a binary file.
I've somewhat figured out that if you would use the original require could work and it does. The problem is the way I do it is very ugly:
options.recursive = true;
options.originalRequire = require;
var myRequire = require('enhanced-require')(module, options);
And then I use it like this:
var Fiber = require.options.originalRequire('fibers');
Any better way? Or should I make an alias and wrap it in a single module?