Building a custom docker image - for external npm package usage

Hi guys,

I’m trying to build a new docker image in order to install some npm packages that I would like to use in the function node. To be more precise, I want to install firebase npm package and perhaps some more (like firebase-auth and firebase-app).

I’ll describe below what I did but my line var firebase = require('firebase'); in the javascript return this error:

VMError: Cannot find module 'firebase'
    at _require (/data/node_modules/vm2/lib/sandbox.js:375:25)
    at /data/packages/nodes-base/dist/nodes:3:16
    at Object.<anonymous> (/data/packages/nodes-base/dist/nodes:36:15)
    at (/data/node_modules/vm2/lib/main.js:1167:29)
    at Object.execute (/data/packages/nodes-base/nodes/Function.node.ts:104:22)
    at Workflow.runNode (/data/packages/workflow/src/Workflow.ts:983:28)
    at /data/packages/core/src/WorkflowExecute.ts:675:41
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

What I did:

  1. I changed the Dockerfile in the n8n-custom folder, with the last 3 lines below:

    Install all needed dependencies

    RUN npm_config_user=root npm install -g full-icu
    RUN npm install -g firebase
    RUN npm install -g firebase-auth
    RUN npm install -g firebase-app

  2. I did a build and pushed to my personal docker repository
    docker buildx build --platform linux/amd64 --build-arg N8N_VERSION=0.126.103 -t mydockeruser/n8n: . -f docker/images/n8n-custom/Dockerfile
    docker push mydockeruser/n8n:

  3. I put on .env at the same folder as docker-compose.yml these lines:

  4. I changed in my docker-compose.yml to pick this pushed image

Am I missing something?

Yes, you have to allow the Function-Node to use the package by setting the environment variable


You can find the documentation here:

Thanks jan for your answer. I have this line in my docker-compose.yml - this isn’t enough?

Ah very sorry, did for some reason overlook your point 3.

Yes, that looks good.

Very strange. It should then work. You could try to add it as a dependency in n8n-nodes-base and rebuild and see if that works. But normally should also work if it is globally installed. Is however possible that it makes a difference for vm2 which we use for that functionality.

1 Like

jan, thanks for your answer!

changing the package.json inside nodes-base makes it work!

In order to avoid forking the repository is there something else I can do to install firebase and make it visible to function node? If not, this already solves my problem!