Referring to a specific module version in the function node?

Is there a way to reference a specific module version when adding modules to a function node?

I tried with a module name like this "mymodule@0.1.0" and the logs showed that this specific version has been installed successfully, but right after the logs says:

 [error] [function:a6b143fb515da793] Error: Cannot find module 'mymodule@0.1.0'
Require stack:
- C:\...\node_modules\mymodule@0.1.0

Regards,
Dirk

You can't do it in a function node, but you can do it in package.json

If you look there after you have installed the module you will see it there, along with a definition of valid versions. Make sure it stipulates only the correct version and it will always be that version. Provided you do not install a different version instead.

Actually you can as I recently discovered. Try it out with the dummy package, try adding aaa@0.0.1 and you will see that it installs that version instead of the latest 0.0.2.

  "dependencies": {
    "aaa": "^0.0.1",
    "read-excel-file": "^5.6.1"
  },

Well, you live and learn.

1 Like

Thanks for your answers!

This is exactly what i tried, adding the module name incl. the version qualifier. It installs the specified version and I see it in the dependencies, but the Node-Red log prompts with "Error: Cannot find module 'mymodule@0.1.0'".
So, referencing a specific in the "Modules" list does not fully work. It installs the modules in the specified version, but it can't load it, because it look for a module name 'mymodule@0.1.0' although it is installed with name 'mymodule'.

My workaround: I will not use 'Modules' feature in the function node, will install the module with a classic "npm install mymodule@0.1.0" in my docker initialization, make it a global requirement in the 'settings.js' and get it via 'const myMod = global.get("mymodule");'

1 Like

Thanks for the update. I think that is actually a bug so you might want to raise an issue against the node-red repo.

Since you can install with a version modifier, node-red should really be able to cope with that or should reject the install. I know that on uibuilder, which has a similar interface for loading npm modules that are mounted as web endpoints, it does cope with version modifiers.