Closed TotallyInformation closed 7 years ago
Need to see how I can handle both locations.
OK, I can see what is going wrong. Newer versions of npm are not installing modules where expected. UI Builder wants them here:
url=/uibuilder/vendor/normalize.css, path=/home/pi/node/nrlive/node_modules/node-red-contrib-uibuilder/node_modules/
but they are actually here:
/home/pi/node/nrlive/node_modules/
I need to work out a way to discover where the front-end modules are actually installed so that I can to an app.use on them which is what makes them available to the front-end.
Trying node package get-installed-path to locate the actual install locations of front-end modules.
You shouldn't need to copy normalize.css or jquery modules manually. uibuilder installs them for you. The updated code from v0.3.4 should fix this.
Please install v0.3.4 from Github with:
npm install totallyinformation/node-red-contrib-uibuilder
in order to try this fix.
You can delete any copied versions of jquery and normalize.css
Either I am doing something wrong or it is still not fixed, unfortunately. I installed the git version 0.3.5 using npm install totallyinformation/node-red-contrib-uibuilder and restarted node-red and still see the error messages. Even more unfortunate I get the same errors even if I copy them to uibuilder/node_modules. Looking at the log I see
Oops, wrong button. To continue, looking at the log I see
2017-09-20T09:13:14.900Z - error: UIbuilder: Failed to add user vendor path - no install found for riot Try doing npm install from <userDir>
2017-09-20T09:13:14.906Z - error: UIbuilder: Failed to add master vendor path - no install found for normalize.css Should have been installed by this module
2017-09-20T09:13:14.907Z - error: Error: get-installed-path: module not found "normalize.css" in path /home/**/node_modules/normalize.css
at Function.getInstalledPathSync [as sync] (/home/**/.node-red/node_modules/get-installed-path/index.js:159:11)
at /home/**/.node-red/node_modules/node-red-contrib-uibuilder/nodes/uibuilder.js:259:56
etc. It seems to be looking in /home/user/node_modules instead of /home/user/.node-red/node_modules.
OK, the first error is because you've not installed riot. In your userDir, you need to do npm install riot --save
.
For the second, I need to know where you do have normalize.css installed. Is it erroring on JQuery as well?
normalize.css
& jquery
should both be in <userDir>/node_modules/
If they aren't, could you please check in <userDir>/node_modules/node-red-contrib-uibuilder/node_modules/
and let me know. Thanks.
Can you define userDir please? Do you mean the user's home directory? I don't have a node_modules there. The root of my node-red project is /home/user/.node_red and normalize and jquery are installed in /home/user/.node-red/node_modules. The error for normalize in comment #3 does suggest that it is looking in /home/user/node_modules rather than /home/user/.node-red/node_modules.
I forgot to say, yes I get the same error for jquery.
userDir is specified in your settings.js. It defaults to the .node-red
folder under your users home folder, e.g. ~/.node-red
which appears to be what you are using.
So it looks like they are in the right place but the get-installed-path module isn't looking in the correct place which is super annoying. It works fine on my Pi & on my Windows installation.
I don't understand. I have just through exactly the same procedure (installing npm from git version) and this time it is working. I suggest leaving this for the moment, if there is a residual issue then no doubt it will re-materialise. Perhaps npm or node had got confused with all my removing and installing different versions. Or perhaps it was me that got confused.
OK, thanks for letting me know. I'm going to add a backup to the get-installed-path
query to make it a bit more robust anyway. But I will work on improving the front-end code to see if I can get rid of your occasional reconnect issue.
Going to close this issue for now. Please feel free to reopen if needed.
Right, I have got to the bottom of this I think. The confusion is that it works if node red is started by: cd ~/.node-red node-red but not if it is started using the systemd service in the pi. The issue is that the service sets the working dir to ~ not to ~/.node-red so getInstalledPath looks in ~/node-modules instead of ~/.node-red/node-modules. getInstalledPath can be given a path I believe. I will modify the code to use userDir and see if that fixes it. I can't work out how to re-open the issue.
In uibuilder.js changing lines 233 and 259 to let installPath = getInstalledPath.sync(packageName, {local:true, cwd: RED.settings.userDir}) fixes it for me. I suppose I should clone the repo and generate a PR but I won't have time today. I will do that if you prefer.
See PR #6
Hi Colin, thanks for the research. I am guessing that you are using the default Node-RED installation? That will be why we are getting different results. I use a custom installation that doesn't use a globally installed version of Node-RED - this is better for a number of reasons I can go into elsewhere if you are interested.
I actually suspect that having working dir set to ~
may be a bug. I think that my systemd script includes a specific folder, I'll need to check.
I think my last addition to that code should catch your case anyway? Using require.resolve(packageName)
should find the correct location except in one case and that is when the module is linked instead of installed normally (as I do when developing). In that case it returns the actual location of the module and not the linked location which is what is required in order for the app.use
to work.
Pain in the butt!
Can you confirm that the current standard code (v0.3.7) does not pick up the module location even without your change?
On balance though, your change is probably correct. Let me think over it a little more before I merge. Just to be sure.
I am using the node-red install generated by the update-nodejs-and-nodered command, which builds the systemd service based on the user running the command. It sets the cwd to the users home, which doesn't seem to cause any problems other than this one. Not sure how it works out to use .node-red, perhaps it is built into the exec command script. I did check that the changes made in v0.3.7 did not fix the problem for me, though I was using an npm link to the cloned repo. Looking in the log I see debug: UIbuilder: Adding master vendor path url=/home/vendor/normalize.css, path=/home/user/.node-red/node_modules/normalize.css/normalize.css and debug: UIbuilder: Adding master vendor path url=/home/vendor/jquery, path=/home/user/.node-red/node_modules/jquery/dist/jquery.js Is that what it should be? My patch works for me for linked and unlinked. Need to look again at the code to understand your comment about the fail falling into the catch. I didn't intentionally change anything other than adding the cwd option, so not sure why it affects the operation on fail.
I am using the node-red install generated by the update-nodejs-and-nodered command, which builds the systemd service based on the user running the command. It sets the cwd to the users home, which doesn't seem to cause any problems other than this one. Not sure how it works out to use .node-red, perhaps it is built into the exec command script. I did check that the changes made in v0.3.7 did not fix the problem for me, though I was using an npm link to the cloned repo.
As I mentioned, a linked module will give the wrong answer from my backup find. I've accepted your change anyway as it looks right. I'll test on my 2 local setups.
Looking in the log I see
debug: UIbuilder: Adding master vendor path url=/home/vendor/normalize.css, path=/home/user/.node-red/node_modules/normalize.css/normalize.css
anddebug: UIbuilder: Adding master vendor path url=/home/vendor/jquery, path=/home/user/.node-red/node_modules/jquery/dist/jquery.js
Is that what it should be?
Yes, that is correct.
My patch works for me for linked and unlinked. Need to look again at the code to understand your comment about the fail falling into the catch. I didn't intentionally change anything other than adding the cwd option, so not sure why it affects the operation on fail.
Don't bother, the comment was rubbish and I removed it :)
Good work, thanks.
Raised by Colin Law: https://groups.google.com/forum/#!topic/node-red/x293sGMhInU
On the working machine I see (from .node-red)
On the pi I see
I copied from the working pc the folders
./node_modules/node-red-contrib-uibuilder/node_modules/normalize.css
and./node_modules/node-red-contrib-uibuilder/node_modules/jquery
to the same place on the pi and now all is working.So it seems the problem is that they are in the wrong place for some reason.