Lighthouse-Automation / node-red-contrib-later

A node red node for triggering using later.js
Other
6 stars 2 forks source link

Fixed reference to auxiliary HTML/JS files. #6

Closed JesseNaranjo closed 7 years ago

d-o commented 8 years ago

OK, so I don't get why this needs changing. As far as I can work out pulling in your change would break the node for everyone who does a standard npm install node-red-contrib-later installation.....what are you trying to achieve?

JesseNaranjo commented 8 years ago

Hi @d-o,

I've actually been able to reproduce the bug described below on three entirely different systems. The bug consists of the Node-RED UI failing to load after installing node-red-contrib-later.

First things first - here is the Node-RED startup info (Node-RED version, Node.js version, etc.):

3 Jun 18:53:39 - [info] Node-RED version: v0.13.4 3 Jun 18:53:39 - [info] Node.js version: v5.11.1 3 Jun 18:53:39 - [info] Linux 4.4.0-22-generic x64 LE 3 Jun 18:53:39 - [info] Loading palette nodes 3 Jun 18:53:39 - [warn] ------------------------------------------ 3 Jun 18:53:39 - [warn] [rpi-gpio] Info : Ignoring Raspberry Pi specific node 3 Jun 18:53:39 - [warn] ------------------------------------------ 3 Jun 18:53:39 - [info] Settings file : /home/jesse/.node-red-data/settings.js 3 Jun 18:53:39 - [info] User directory : /home/jesse/.node-red-data/ 3 Jun 18:53:39 - [info] Flows file : /home/jesse/.node-red-data/flows.json 3 Jun 18:53:39 - [info] Creating new flow file 3 Jun 18:53:39 - [info] Starting flows 3 Jun 18:53:39 - [info] Started flows 3 Jun 18:53:39 - [info] Server now running at http://127.0.0.1/

For reference, here is my npm list -g and npm list (Node-RED is installed, but before node-red-contrib-later). The Node-RED UI loads fine, as shown below: Node-RED UI Works

However, after installing node-red-contrib-later (npm list with node-red-contrib-later), you can see that the browser can no longer load the Node-RED UI: Node-RED UI Not Working

Now, if I manually edit the file later.js (located at <node-red-install-dir>/node_modules/node-red-contrib-later/later/), and perform the following changes from:

fs.readFile(path.resolve(__dirname, "../node_modules/later/" + req.params.file), function (err, data) {

to

fs.readFile(path.resolve(__dirname, "../../later/" + req.params.file), function (err, data) {

The Node-RED UI loads again. The reason that this change is required is because the path "../node_modules/later/" (referring to <node-red-install-dir>/node_modules/node-red-contrib-later/node_modules/later/) does not exist. So, the change to "../../later/" (referring to <node-red-install-dir>/node_modules/later/) will, in turn, serve the correct files.

My apologies for the long-winded post, but I just wanted to make sure I covered the bug correctly.

Thanks, Jesse

TotallyInformation commented 7 years ago

I concur, this error makes the node useless when using Node.JS v6+

d-o commented 7 years ago

I think it is the flat npm structure causing this. I recently posted to the mail group on this issue (on phone can't post link). Again will triage before the end of the weekend.

d-o commented 7 years ago

I have fixed this issue, and added a more robust fallback if the file load still fails. It should no longer crash the browser.