I am trying to use nodemailer for emails as I need to use proxies to connect to smtp.
include it in a node code as follows:
const nodemailer = require(‘nodemailer’);
The error I am getting when executing this node:
Cannot find module ‘nodemailer’ [line 1]
What is the error message (if any)?
Cannot find module ‘nodemailer’ [line 1]
Additional information
I have tried a million things by now. I have created a Dockerfile and package.json on github.
Latest Dockerfile content:
FROM n8nio/n8n:latest
USER root
WORKDIR /home/node/.n8n/nodes
RUN npm install -g [email protected] https-proxy-agent --unsafe-perm
in Coolify I have set two environment variables N8N_NODE_FUNCTION_ALLOW_EXTERNAL and NODE_FUNCTION_ALLOW_EXTERNAL that both have value nodemailer,https-proxy-agent
I have ran npm install nodemailer in /.n8n/nodes/
In the coolify ssh terminal I can see it’s nodemailer is installed in /.n8n/nodes/node_module.
I have also tried setting a node_path variable in the environment variable in the n8n resource.
At this point, I am not sure if anything hah. What do you suggest:
A) how I can check which path n8n checks for modules
B) how I can check if the module is in that location (I assume go there with SSH and if there is a directory “nodemailer”, that should be installed?)
No reason at all, if installed even better. But that doesn’t make sense, because I got the error that nodemailer was not found when I add thia in a code node:
const nodemailer = require(‘nodemailer’);
If it was installed by default, I shouldn’t have received that error right?
I did run this code:
// This code uses the standard Node.js process object to read
// the environment variable.
const allowedModules = process.env.NODE_FUNCTION_ALLOW_EXTERNAL;
// Check if the variable is defined
if (allowedModules) {
console.log(NODE_FUNCTION_ALLOW_EXTERNAL is set to: ${allowedModules});
} else {
console.log(‘NODE_FUNCTION_ALLOW_EXTERNAL is NOT set.’);
}
// Return the value as output
return [{ json: {
NODE_FUNCTION_ALLOW_EXTERNAL: allowedModules,
status: allowedModules ? ‘Set’ : ‘Not Set’
} }];
And the output is:
[Node: “Code in JavaScript”] NODE_FUNCTION_ALLOW_EXTERNAL is NOT set.
So apparently that’s the issue, which is weird as it’s specifically set as seen in the screenshot above.
Because I was so sure I set it, I googled differently and found this:
“for compose based projects/services you need to add the env to the compose file in the ui, this will create the desired entries on the env tab for you to fill in, it doesn’t work the otehr way around”