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

Require error with [email protected] #43

Closed
blond opened this issue Jun 1, 2015 · 6 comments
Closed

Require error with [email protected] #43

blond opened this issue Jun 1, 2015 · 6 comments

Comments

@blond
Copy link
Contributor

blond commented Jun 1, 2015

In [email protected] were changes with requirenodejs/node#1801

For real file system require works well, but with mock-fs fail with error.

How to reproduce:

var path = require('path'),
    fs = require('fs'),
    mock = require('mock-fs');

mock({
    'file.js': 'module.exports = 10;'
});

var filename = path.resolve('file.js'),
    contents = fs.readFileSync(filename, 'utf-8');

// File exists
console.log(contents); // module.exports = 10;

var val = require(filename); // throw error

console.log(val);

Expected:

module.exports = 10;
10

Actual:

module.js:334
    throw err;
          ^
Error: Cannot find module '/Users/blond/projects/mock-test/file.js'
    at Function.Module._resolveFilename (module.js:332:15)
    at Function.Module._load (module.js:282:25)
    at Module.require (module.js:361:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/blond/projects/mock-test/index.js:14:11)
    at Module._compile (module.js:426:26)
    at Object.Module._extensions..js (module.js:444:10)
    at Module.load (module.js:351:32)
    at Function.Module._load (module.js:306:12)
    at Function.Module.runMain (module.js:467:10)

@causal-agent
Copy link

Doesn't look like there would be any way to fix this in mock-fs 😞

@blond
Copy link
Contributor Author

blond commented Jun 4, 2015

May be need to mock Module.require?

ericlathrop added a commit to ericlathrop/unfold that referenced this issue Jul 20, 2015
See tschaub/mock-fs#43
Either way, it's nice to have the test plugins as standalone files for
syntax highlighting purposes.
@tschaub
Copy link
Owner

tschaub commented Nov 29, 2015

Please reopen if this is still an issue with the latest Node. We may need to document it as a limitation.

@tschaub tschaub closed this as completed Nov 29, 2015
@blond
Copy link
Contributor Author

blond commented Feb 11, 2016

The same problem with [email protected] and [email protected].

@rndD
Copy link

rndD commented Feb 12, 2016

👍 reproduced this error in Node 4.x.

@qfox
Copy link

qfox commented Feb 17, 2016

@tschaub What do you think about mocking require (or something) in node 4.x+ via public API?

blond pushed a commit to enb/mock-enb that referenced this issue Apr 20, 2016
In most ENB packages used `mock-fs` to testing.

The `mock-fs` does not support `require` for `Node.js 4`: tschaub/mock-fs#43.

Because of this `node.runTechAndRequire()` will throw error:

```
Cannot find module 'path/to/file.js'
```
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

5 participants