jperkin / node-rpio

Raspberry Pi GPIO library for node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot resolve fs when trying to compile

maximus1127 opened this issue · comments

Hi there, I'm very excited to use your package. It's very well documented and seems very powerful. I'm having a problem though. When I try to compile, it gives me this error:

ERROR in ./node_modules/bindings/bindings.js
Module not found: Error: Can't resolve 'fs' in '/var/www/myproject/node_modules/bindings'
 @ ./node_modules/bindings/bindings.js 5:9-22
 @ ./node_modules/rpio/lib/rpio.js
 @ ./resources/js/app.js
 @ multi ./resources/js/app.js ./resources/sass/app.scss

ERROR in ./node_modules/rpio/lib/rpio.js
Module not found: Error: Can't resolve 'fs' in '/var/www/myproject/node_modules/rpio/lib'
 @ ./node_modules/rpio/lib/rpio.js 18:9-22
 @ ./resources/js/app.js
 @ multi ./resources/js/app.js ./resources/sass/app.scss

I don't know how to fix this as the 'fs' module doesn't even seem to be available to download anymore. Can you offer any advice?

fs is a core node module. Looking around for similar error messages suggests you might be using webpack or similar? This module only works on real hardware, you can't run it in a browser.

oh really? yes you're right, i am using webpack. this is my first time exploring a project like this, could I trouble you for some advice? what do you mean "real hardware"? I'm hosting this project on the pi itself with apache. I'm trying to use WebRTC to have real time controls. As that's based on javascript, I was trying to control the GPIO's through browser based data signals. Is there anyway that you're aware of to do this? Or do I just have to make ajax calls to local python scripts?

But i'm more interested in how to use your library specifically. Suppose I convert this project into a full node.js application, how would I go about running your library on that? I'm still not understanding what it means when it "only works on real hardware" and not in a browser.

webpack-node-externals might be something for you

By real hardware I mean that the module requires direct access to the file system, specifically interacting with the kernel via /dev/mem or /dev/gpiomem, and any browser-based environment will not permit you to do this.

Usually if you want to write a web application you'd split it into two parts, one running on the server talking to the hardware and exposing a REST API, then a frontend that talks to the API over HTTP and provides an interface for the user to interact with it.