[Load custom JavaScript file] Error on var rpio = require('rpio');

Discussions about RaZberry - Z-Wave board for Raspberry computer
Post Reply
billyboy
Posts: 61
Joined: 16 Mar 2013 21:33

[Load custom JavaScript file] Error on var rpio = require('rpio');

Post by billyboy »

When I try to load a custom LavaScript file To control GPIO on my Raspberry I get a error loading the file.
I hooked up a shift register to some GPIO's and therefore including the next line in my code:
var rpio = require('rpio');

When I run my JavaScript file with "node myCode.js" there is no problem, rpio is installed.

But when loading my file I get next error:
[2018-10-24 14:09:07.022] [core] Instantiating module 16 from class CustomUserCodeLoader
[2018-10-24 14:09:07.022] [core] --- Starting module Load custom JavaScript file
[2018-10-24 14:09:07.116] [core] Executing script: //myCode.js
...
[2018-10-24 14:09:07.125] [E] [core] result: Error: ReferenceError: require is not defined
at automation/myCode.js:7:12
at automation/modules/CustomUserCodeLoader/index.js:39:4
at Array.forEach (native)
at CustomUserCodeLoader.init (automation/modules/CustomUserCodeLoader/index.js:34:30)
at AutomationController.instantiateModule (automation/classes/AutomationController.js:488:13)
at AutomationController.createInstance (automation/classes/AutomationController.js:931:17)
at ZAutomationAPIWebRequest._.extend.createInstance (automation/ZAutomationAPIProvider.js:1177:31)
at ZAutomationAPIWebRequest.ZAutomationWebRequest.handleRequest (automation/WebserverRequestRouter.js:259:35)
at automation/WebserverRequestRouter.js:32:29
at WebServer.document_root (automation/Webserver.js:35:11)
[2018-10-24 14:09:07.128] [core] Notification: error (core): Cannot instantiate module: CustomUserCodeLoader: Error: Uncaught ReferenceError: require is not defined
[2018-10-24 14:09:07.137] [core] Error: Uncaught ReferenceError: require is not defined
at Error (native)
at automation/modules/CustomUserCodeLoader/index.js:39:4
at Array.forEach (native)
at CustomUserCodeLoader.init (automation/modules/CustomUserCodeLoader/index.js:34:30)
at AutomationController.instantiateModule (automation/classes/AutomationController.js:488:13)
at AutomationController.createInstance (automation/classes/AutomationController.js:931:17)
at ZAutomationAPIWebRequest._.extend.createInstance (automation/ZAutomationAPIProvider.js:1177:31)
at ZAutomationAPIWebRequest.ZAutomationWebRequest.handleRequest (automation/WebserverRequestRouter.js:259:35)
at automation/WebserverRequestRouter.js:32:29
at WebServer.document_root (automation/Webserver.js:35:11)

Please advice me
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: [Load custom JavaScript file] Error on var rpio = require('rpio');

Post by PoltoS »

Require is a nodejs specific call. Adopt your code to native JavaScript
Post Reply