Requiring modules in Node.js: Everything you need to know
Samer Buna
1.6K18

First, -thank you for sharing your insight.

I have an application that needs to download npm packages at run-time. This has all worked fine, until we deployed the application as a *snap* to Ubuntu Core. This left the original app on a write protected area, and all run-time installed packages in the home directory (~/home/use/node_modules). And this was where the issues came :(

As I wanted to leave the application as is (as much as possible), I didn’t want to create my own require method, but just adding the path to the home directory when starting the application.

The original application was then able to load the run-time installed packages, but those packages were not able to find other packages anywhere (not in it’s own node_modules folder, nor in the root).

I think I get the same issue (symptoms are the same) if I try to require a package from a different part of the disk, after added the path to the process.env.NODE_PATH variable.

Q: Is there a better (working) way to solve this, without overriding the require method?

Again, Thank you

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.