-
Notifications
You must be signed in to change notification settings - Fork 225
Fix Uncaught Type Error #168
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this, just a few nits
fs = require('fs'); | ||
fs = require('fs'); | ||
if (!fs.readFileSync) { | ||
// If fs is empty, we are in the browser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it's not empty, it's: https://www.npmjs.com/package/browserify-fs
How about:
try {
fs = require('fs');
if (!fs.existsSync || !fs.readFileSync) {
// fs doesn't have all methods we need
fs = null;
}
} catch (err) {
/* noop */
}
also, please keep the indentation at 2 spaces :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well we don't use browserify-fs
plugin so without this it we don't have a functionnal fs
.
node-browserify
default builtins are defined here https://github.com/substack/node-browserify/blob/8f5ebbf50544bdbdf34d4e0f336ac531152a5da4/lib/builtins.js
For the code comment I'll fix that right away
@LinusU comments applied and commit amended |
Fixes #167 Since version 0.4.9, we require `fs` but it should fail if we are in a browser. However, `browser-source-map-support.js` is bundled with browserify which converts unsupported builtins to empty object. See https://github.com/substack/node-browserify/blob/8f5ebbf505/lib/builtins.js#L12 This PR checks if required `fs` contains `readFileSync` which is part of `fs` API.
Amended again for 2 spaces indentation |
@@ -4,6 +4,10 @@ var path = require('path'); | |||
var fs; | |||
try { | |||
fs = require('fs'); | |||
if (!fs.readFileSync || !fs.readFileSync) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a typo here, one of them should be existsSync
Chiming in with that this is breaking https://github.com/tschaub/karma-source-map-support for us. Would be most grateful for a fix :) |
Same issue for me. Would be nice to have a fix merged quickly. |
@LinusU oops sorry for that. Just fixed it. |
Thanks! |
Released as 0.4.10 |
Fixes #167
Since version 0.4.9, we require
fs
but it should fail if we are ina browser. However,
browser-source-map-support.js
is bundled withbrowserify which converts unsupported builtins to empty object. See
https://github.com/substack/node-browserify/blob/8f5ebbf505/lib/builtins.js#L12
This PR checks if required
fs
containsreadFileSync
which is partof
fs
API.Tests:
Then open http://127.0.0.1:1336/browser-test/