Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Error: Cannot find module" when specifying function node module version #4541

Open
JoshuaCWebDeveloper opened this issue Jan 23, 2024 · 1 comment

Comments

@JoshuaCWebDeveloper
Copy link
Contributor

Current Behavior

A function node species a specific version of a module:
image

When it is deployed, it correctly installs the specified version of the package; however, it fails to import it:

23 Jan 20:24:47 - [info] Stopping flows
23 Jan 20:24:47 - [info] Stopped flows
23 Jan 20:24:47 - [info] Updated flows
23 Jan 20:24:47 - [info] Installing module: pkginfo, version: 0.3.1
23 Jan 20:24:49 - [info] Installed module: pkginfo@0.3.1
23 Jan 20:24:49 - [info] Starting flows
23 Jan 20:24:49 - [error] [function:e4571de5204a6558] Error: Cannot find module 'pkginfo@0.3.1'
Require stack:
- /data/node_modules/pkginfo@0.3.1
23 Jan 20:24:49 - [info] Started flows

This was reported in the forums last year; however, I couldn't find an issue on GitHub about it.
https://discourse.nodered.org/t/referring-to-a-specific-module-version-in-the-function-node/76633

Expected Behavior

When a function node specifies a specific version of a module to install, that module should also be imported successfully.

Steps To Reproduce

Attempt to deploy and execute the sample flow.

Example flow

[
    {
        "id": "95af9ddfec641040",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "e4571de5204a6558",
        "type": "function",
        "z": "95af9ddfec641040",
        "name": "function 7",
        "func": "\nreturn {version: pkginfo.version};",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [
            {
                "var": "pkginfo",
                "module": "pkginfo@0.3.1"
            }
        ],
        "x": 1080,
        "y": 240,
        "wires": [
            [
                "4ebef47db4a17322"
            ]
        ]
    },
    {
        "id": "485563aa4f728dd0",
        "type": "inject",
        "z": "95af9ddfec641040",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 900,
        "y": 220,
        "wires": [
            [
                "e4571de5204a6558"
            ]
        ]
    },
    {
        "id": "4ebef47db4a17322",
        "type": "debug",
        "z": "95af9ddfec641040",
        "name": "debug 18",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1300,
        "y": 240,
        "wires": []
    }
]

Environment

  • Node-RED version: 3.1.3
  • Node.js version: 16.20.2
  • npm version: 8.19.4
  • Platform/OS:
    Docker image: nodered/node-red:3.1.3
    Docker host: Linux 6e93128c6163 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 Linux
  • Browser: Microsoft Edge 120.0.2210.144 (Official build) (64-bit)
@JoshuaCWebDeveloper
Copy link
Contributor Author

Workaround:

After attempting to deploy with the specific version (and the correct version being installed), simply remove the version specifier from the module definition in the function node. Node-RED will use the currently installed version of the module and correctly import it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant