Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node fibers throw an error when used with enhanced require #10

Open
bitplanets opened this issue Dec 30, 2014 · 0 comments
Open

Node fibers throw an error when used with enhanced require #10

bitplanets opened this issue Dec 30, 2014 · 0 comments

Comments

@bitplanets
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant