0

I've inherited a project that does its build using NodeJS. Everything's been working fine for us for months. We've built a number of production releases with no problem.

Enter xlsx.js.

Since adding this package as a dependency, we've found that our Gulp build works on Windows but not on Ubuntu (which is our build machine). When we do the build on Ubuntu, RequireJS barfs on require('fs'):

johnny@ubun-16:~/dev/eVGM-JavaScript-Client$ node --version
v4.6.1
johnny@ubun-16:~/dev/eVGM-JavaScript-Client$ gulp test
[15:19:35] Using gulpfile ~/dev/eVGM-JavaScript-Client/gulpfile.js
[15:19:35] Starting 'test'...
[15:19:35] Starting 'run-tests'...
07 11 2016 15:19:40.236:WARN [karma]: No captured browser, open http://localhost:9876/
07 11 2016 15:19:40.298:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
07 11 2016 15:19:40.308:INFO [launcher]: Starting browser PhantomJS
07 11 2016 15:19:41.421:INFO [PhantomJS 2.1.1 (Linux 0.0.0)]: Connected on socket Hq69p1CiIhcsCDOGAAAA with id 72071968
07 11 2016 15:19:41.596:WARN [web-server]: 404: /base/jspm_packages/system-polyfills.js
07 11 2016 15:19:43.457:WARN [web-server]: 404: /base/fs.js
PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  Error: (SystemJS) XHR error (404 Not Found) loading /home/johnny/dev/eVGM-JavaScript-Client/fs.js
Error loading /home/johnny/dev/eVGM-JavaScript-Client/fs.js as "fs" from /home/johnny/dev/eVGM-JavaScript-Client/jspm_packages/github/sheetjs/js-xlsx@0.8.0/xlsx.js

PhantomJS 2.1.1 (Linux 0.0.0): Executed 0 of 0 ERROR (2.27 secs / 0 secs)

From what I can tell, 'fs' is a built-in package for NodeJS. (right?) And it should be there. Yet it's not according to Gulp.

To make matters even weirder, if I type Node and at the Node prompt, type "require('fs')", I get the flood of text that tells me that Node is finding the package A-OK.

Maybe it's a Gulp issue. Maybe it's a Ubuntu issue. Maybe it's a Jeff's-an-idiot issue. For whatever reason, I can not get our build to find fs from Gulp, and only on Ubuntu.

Any help very, very gratefully received ...

Thanks, Jeff

Jeffrey Getzin
  • 531
  • 1
  • 6
  • 11
  • Could this be some kind of path issue? In other words, does fs.js reside in some magic NodeJS directory that our Windows installation knows about but our Ubuntu installation does not? – Jeffrey Getzin Nov 07 '16 at 21:15

2 Answers2

0

Ok, i figured it out, digging through some related StackOverflow answers.

require('fs') is only intended to be used on a server application. After all, what is the file system of a browser? It makes no sense in that context. If I'd been using my brain I would have realized that.

So I looked at where the library was using fs, and it was only in a single place:

var fs;
function readFileSync(filename, options) {
  if(fs === undefined) fs = require('fs');
  return parse(fs.readFileSync(filename), options);
}

I stuck an alert in there and ran the code we needed; the alert was not called.

That means that even though fs.js is loaded it is not actually used when executing in the browser for our application.

So the next step is probably to make a custom version of the library (a fork) and remove that single function. We don't need it and it breaks our build, so we can get rid of it.

Does this make sense?

Jeff

Jeffrey Getzin
  • 531
  • 1
  • 6
  • 11
0

Do not fork, the library is made for both client and server side, it's normal to find this.

I've inherited a project that does its build using NodeJS. Everything's been working fine for us for months. We've built a number of production releases with no problem.

Inheritance these days :)

So correct me if I'm wrong, it's a javascript client side project build with gulp (using node). You added xslx and your test works fine on windows but not on ubuntu.

My first suspect is phantomJS. Check your version. It may be related to https://github.com/SheetJS/js-xlsx/issues/184

Boris Charpentier
  • 3,515
  • 25
  • 28
  • Interesting thought! Yes, I have a client-side project building with Gulp and the behavior is exactly as you say. I'll check out that link! Thank you! – Jeffrey Getzin Nov 08 '16 at 13:41
  • Oh, but wait. I just remembered: I tried the tests using Firefox in Karma instead and encountered the same problem. I don't recall my browser engine phylogeny, so I suppose it's possible they suffer from the same problem ... – Jeffrey Getzin Nov 08 '16 at 13:44
  • that's a good suggestion. Our build guy is out today but I'll try that tomorrow when he's in to see if that does the trick. That sure seems like the _cleanest_ solution if it works. – Jeffrey Getzin Nov 08 '16 at 14:36
  • Now I can't get BrowserFS to work. It doesn't come with a dist directory and I can't get it to build using the instructions in the readme. – Jeffrey Getzin Nov 09 '16 at 16:16
  • I think a fork may be the way I have to go. I just don't have the luxury of time to go down the rabbit hole on this right now. – Jeffrey Getzin Nov 09 '16 at 16:17
  • 1
    Thank you very much for trying though! :) – Jeffrey Getzin Nov 09 '16 at 16:27