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

[1.3-rc.8] possible issue with third-party lib on client, cannot find module 'fs' #6578

Closed
markshust opened this issue Mar 23, 2016 · 13 comments
Assignees
Milestone

Comments

@markshust
Copy link

I put together a sample repo of this bug at: https://github.com/markoshust/meteor-keen-js

I don't know if the bug is caused by Meteor, or by the keen-js npm lib. However, I'm receiving the following error in the client when running it:

Uncaught Error: Cannot find module 'fs'
@jdrydn
Copy link

jdrydn commented Mar 23, 2016

If Meteor doesn’t use the standard node libraries or hasn’t mocked fs properly then that’s the error you’re gonna see!

@markshust
Copy link
Author

Tagging #6266

@benjamn
Copy link
Contributor

benjamn commented Mar 23, 2016

You can install whatever mock Node libraries you want, but an easy way to install them all is to do npm install meteor-node-stubs in your app directory.

@markshust
Copy link
Author

Thanks @benjamn -- installed meteor-node-stubs, now receiving this error:

Uncaught TypeError: fs.readFileSync is not a function

@awwx
Copy link
Contributor

awwx commented Mar 23, 2016

@markoshust are you seeing this error on the server or on the client?

(You can stub fs on the client but it's not going to be able to do file operations).

@markshust
Copy link
Author

Here's a profile if it helps at all: https://gist.github.com/markoshust/32d9eac050e1ab1ed893

and error detail:

screen shot 2016-03-23 at 2 18 43 pm

screen shot 2016-03-23 at 2 05 44 pm

@benjamn
Copy link
Contributor

benjamn commented Mar 23, 2016

@awwx is correct; perhaps this Mime package is not meant to be used on the client?

@markshust
Copy link
Author

Weird, if I remove the import keen, and do an import mime from 'mime' at the top of the script, everything runs ok. So the mime npm module appears to be client-compatible. Also tried the same with superagent, all ok. Something wonky is going on here.

@benjamn
Copy link
Contributor

benjamn commented Mar 23, 2016

Yeah, some modules work on the client if you carefully/accidentally avoid using their server-only parts. This is true of Browserify and Webpack bundles, too. Not ideal, but not unexpected.

@benjamn benjamn self-assigned this Mar 24, 2016
@benjamn benjamn added this to the Release 1.3 milestone Mar 24, 2016
@AlexFrazer
Copy link

The meteor-node-stubs seems to be missing a few modules, namely those involved in I/O, such as net and fs

I am really looking for a net related solution. Eg, when I use net.connect({ port: 23, host: '192.168.1.3' }, function () { }), it will run as a simulation on the client, but connect on the server and return to the callback on the client when the connection has been established.

@benjamn
Copy link
Contributor

benjamn commented Mar 24, 2016

The support we provide for client-side Node built-in libraries is virtually identical to what Browserify and Webpack provide, because that's what client-compatible npm packages have come to expect:

Note that fs and net are there (in fact, every built-in module is represented), though some are implemented as empty stubs. Feel free to submit a pull request if you think something should be improved, but please bear in mind we're not interested in hacks that narrowly support specific use cases. If you have special needs, consider using a package with a different name, or forking meteor-node-stubs, or monkey-patching the modules it returns.

@benjamn benjamn closed this as completed Mar 24, 2016
@markshust
Copy link
Author

Thanks for the feedback.

FYI, this appears to be caused by an outdated library (superagent). Upgrading the dep of the keen-js module to a more recent version of superagent seems to resolve the issue.

@chmanie
Copy link

chmanie commented Jul 7, 2016

In browserify you can actually use https://github.com/substack/brfs to inline readFileSync calls. That won't help in this case, I guess but such kind of transform pipeline would come in handy in meteor as well.

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

6 participants