Skip to content

RED.import (importModule) cannot correctly handle aliased exports #5434

@qc00

Description

@qc00

Current Behavior

  1. Say there's a module M.js in a package pkg that uses the exports section in package.json to alias/remap internal paths.
  2. The M.js file is in the pkg/dist folder, but I put pkg/M.js as the "Module name" in a Node RED custom function
  3. Node RED will report Error: Cannot find module at run-time
  4. The "Require stack" will point to $node_red_home/node_modules/pkg/M.js which does not exist

Expected Behavior

require('pkg/M.js') obviously work just fine from node, so should be supported by Node RED custom function import.

I believe this line should reference parsedModule.module, so the moduleDir is always a real directory.

Steps To Reproduce

No response

Example flow

No response

Environment

  • Node-RED version: affects all versions since RED.import was introduced
  • Node.js version: 20
  • npm version:
  • Platform/OS:
  • Browser:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions