Search code examples
node.jsnpmnode-red

Node-RED cannot find local module


I am developing a Node-RED Custom Node in TypeScript using a Nx monorepository with following hierarchy:

reponame
 + packages
 | + package-a
 | + package-b
 | + custom-node

The Custom Node imports package-b which imports package-a via import { TestClass } from "@reponame/package-b". I performed npm installs in each package and it compiles to my repo's ./dist/ like a charm.

Now I'm struggeling to get my Custom Node into Node-RED. I did npm install pathToRepo/dist/packages/custom-node and the same for package-a and package-b. However, when starting Node-RED this error is raised: Error: Cannot find module '@reponame/package-b' in the .js-file containing the Custom Node. In other words, my local dependencies in my custom node could not be resolved. In addition to that, other dependecies on modules from the internet seem to be also NOT found.

I tried to do npm install package-b inside pathToNodeRed/node_modules/@reponame/custom-node but that did not work as it through errors while trying to fetch package-a from the internet.

How can I correctly resolve this issue?


Solution

  • Installing all dependencies including the local ones on monorepo level helped.

    Just perform npm install <path to package> in /reponame for every dependency and delete the dependencies in each package using npm uninstall <module name>.