Hello, I'm trying to create nodes that connect to an API, I wanted to use fetch (node-fetch) which seems to me a simple solution to make requests to the API. But when I test my node, it sends me the error :
[ERR_MODULE_NOT_FOUND]: Cannot find package 'node-fetch' imported from <directory of node>
I did however declare it in my package.json :
and I wanted to import it with this code placed at the first line of my .js document of the node :
I think that the problem here is that when running in a development mode, I don't think that your node module is checking what would normally be the "parent" folder, e.g. the Node-RED userDir.
For testing, make sure that you run npm install in the node package's folder and it should work. This sorts itself out when running in a more production mode where you've installed the node via npmjs.org or GitHub.
Just make sure that you have a .gitignore file in your module folder that excludes node_modules.
This is indeed the behavior to see, once the node-fetch package is installed in my package folder, it works very well!
In my case, this loads all the "node_modules" folders from the node folder, up to the root of the disk which is my dev disk (D:) but my instance of Node RED is running on my main disk (C :), I think this explains it.
Infact when installing the package I'm developing with the path to the folder on D:\ disk, it create a symlink to this folder in the "node_modules" folder of my Node RED instance, so it couldn't find "node-fetch" which was installed in this folder...
Thank you very much for your help, I will be able to continue my development and I hope to be able to offer a new package of nodes soon to the community!