Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

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

@bitplanets

Description

@bitplanets

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions