Ignore SSL issues with `axios` and docker | Import `https` package with docker

The problem

I have a complex code node which uses axios package. The axios package in already included in the n8n docker image. Everything is working fine until I faced a website without certificate. I need to ignore SSL issues with axios.

I found a simple solution:

const axios = require('axios');
const https = require('https');

const instance = axios.get("https://example.com", {
  httpsAgent: new https.Agent({  
    rejectUnauthorized: false
  })
});

I have a Dockerfile to create a custom n8n image:

FROM n8nio/n8n:latest
USER root
RUN npm install -g https puppeteer
USER node

I build my docker image with:

sudo docker build . -f Dockerfile -t custom-n8n

I run my container with:

-e NODE_FUNCTION_ALLOW_EXTERNAL="https,puppeteer"

The issue

When running the following code, axios and puppeteer packages are succesfully imported but https is not found:

const axios = require('axios');
const puppeteer= require('puppeteer');
const https = require('https');

The resolution

Solution 1
Regarding this comment, I can set env variable NODE_TLS_REJECT_UNAUTHORIZED to 0 but it applies to the entire container.

Solution 2
Use native fetch method with undici

Solution 3
Find a way to import https package.

The questions

  1. How can we import https package ?
  2. Can’t I import it because it is not compatible with Reactnative/Vuejs ?

Information on your n8n setup

  • n8n version: 1.37.3
  • Database: SQLite
  • n8n EXECUTIONS_PROCESS setting: own
  • Running n8n via Docker
  • Operating system: Rasbian Lite 64bits

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @LucBerge,

I don’t see why it wouldn’t work as we also use https in n8n, Have you tried adding it to the internal env option to see if that helps?

This is the full error message I have when importing https package:

VMError: Cannot find module '/usr/local/lib/node_modules/https'
    at LegacyResolver.loadAsPackage (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver.js:427:11)
    at LegacyResolver.loadAsDirectory (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver.js:439:15)
    at LegacyResolver.loadNodeModules (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver.js:457:13)
    at LegacyResolver.resolveFull (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver.js:310:12)
    at LegacyResolver.resolveFull (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver-compat.js:147:17)
    at LegacyResolver.resolve (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/resolver.js:121:15)
    at resolve (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/nodevm.js:317:21)
    at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/bridge.js:485:11)
    at requireImpl (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/setup-node-sandbox.js:90:19)
    at require (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/setup-node-sandbox.js:171:10)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:1:112
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:4:2
    at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/bridge.js:485:11)
    at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/nodevm.js:497:23)
    at JavaScriptSandbox.runCodeEachItem (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/JavaScriptSandbox.js:97:45)
    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/Code.node.js:139:40)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:728:42)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:660:68
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:1062:20

Have you tried adding NODE_FUNCTION_ALLOW_BUILTIN and setting it to https?

1 Like
 -e NODE_FUNCTION_ALLOW_BUILTIN="*" \
 -e NODE_FUNCTION_ALLOW_EXTERNAL="*" \

Setting to *, I won’t have import issues anymore…

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.