-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Browserify: fs.readFile is not a function (v 3.1.0) #1018
Comments
To browserify jsdom, you need to have another project that does |
Thank you domenic for clarification. (function () {
var jsdom = require('jsdom');
module.exports = jsdom;
}()); Then: and in the HTML page: <script src='/src/lib/jsdom_browserify.js'></script>
<script>
jsdomCapsule = require('jsdom_capsule');
jsdomCapsule.env( ... );
</script> But the browser's error console still yields:
|
It's possible we've introduced a regression recently, but it seems unlikely, given how we are running tests on the browserified code every build. I'll try to look into this more. I assume you're using the latest version of browserify? |
Latest version, browserify 8.1.3. The line referred to by my browser's error console is pastebin here (highlighted). |
I stripped down the HTML part to the minimal, to no avail: <script src='/src/lib/jsdom_browserify.js'></script>
<script>
jsdomCapsule = require('jsdom_capsule');
jsdomCapsule.env(
'<div></div>',
function (errors, window) {
console.log('message');
}
);
</script> Produces: "TypeError: fs.readFile is not a function" |
This is not a regression.
All them present the same exact error on browser's console: "TypeError: fs.readFile is not a function". Test method:The test method is the same as for my previous posts:
(function () {
var jsdom = require('jsdom');
module.exports = jsdom;
}());
<script src='/src/lib/jsdom_browserify.js'></script>
<script>
jsdomCapsule = require('jsdom_capsule');
jsdomCapsule.env(
'<div></div>',
function (errors, window) {
console.log('message');
}
);
</script> No errors nor any stdout printed by |
Ahh, looks like in our CI runs we include browser-fs.js, which is why it works in our tests. Can you try your html with: <script src='/src/lib/jsdom_browserify.js'></script>
<script>
jsdomCapsule = require('jsdom_capsule');
jsdomCapsule.env({
html: '<div></div>',
done: function (errors, window) {
console.log('message');
}
});
</script> This should not call |
Wow, thank you @Sebmaster, that works. |
@Sebmaster we should probably add |
@domenic Not too sure about the automatic XHRs, but it's probably for the best. |
To support DOM in HTML5 web workers, I do:
$ browserify -r /usr/local/lib/node_modules/jsdom/lib/jsdom.js:jsdom >jsdom_browserify.js
In the HTML page:
On the browser (Iceweasel 31) console I get:
TypeError: fs.readFile is not a function jsdom_browserify.js:49261
jsdom version: 3.1.0
I read a
Domenic
's post from here dated Oct 10, 2014 stating "jsdom works in the browser with browserify now".I guess he refers to jsdom version 1.0.1 or 1.0.2, released during that time.
Am I correct? Do newer jsdom releases work with browserify? Would an older version work on browsers?
The text was updated successfully, but these errors were encountered: