Importing module gives error

Hi all!

Just started experimenting with external modules.

I installed @hashgraph/sdk , but keep getting the error “ERROR: Cannot find module ‘@hashgraph/sdk’ [line 1]”
image

To double check if everything else was in working error, I did the same with the module ‘moment’. Moment is working perfectly.

What am I doing wrong here? Is it because it contains an ‘@’ or ‘/’ ? or is it something that is inherently wrong with the hasgraph sdk?

Thanks!

edit: obviously this is on a self-hosting instance (one that I use for experimenting next to my cloud version)

Hey @bees8,

How did you import the module? Looking at the error it has either not been imported correcly or NODE_FUNCTION_ALLOW_EXTERNAL has not been set to include it.

Hey Jon! Thanks for your reply.
We tried so many things and I was barely able to follow lol.
But in short, in the end we managed to install @hashgraph/sdk and it worked in n8n! However, once we would restart docker it would be removed again.

So my friend came up with a solution using a docker file:

USER root
RUN npm install --save @hashgraph/sdk
USER node

and in docker-compose:

build:
      dockerfile: Dockerfile

This gave us a “invalid host header” error (no idea what it means).

We also tried directly adding it directly to the docker compose file:

command: cd /usr/local/lib/node_modules/n8n && npm install --save @hashgraph/sdk && n8n start

But that gave us an instance that was not able to start (status was ‘restarting’)

Maybe the solution is super obvious! no idea…

I’m running this n8n instance on digitalocean, installed using the digital ocean tutorial :slight_smile:

Got it to work!
This is my docker-compose.yml

  GNU nano 7.2                                                                           docker-compose.yml                                                                                    
version: "3.7"

services:
  caddy:
    image: caddy:latest
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - caddy_data:/data
      - ${DATA_FOLDER}/caddy_config:/config
      - ${DATA_FOLDER}/caddy_config/Caddyfile:/etc/caddy/Caddyfile

  n8n:
#    image: docker.n8n.io/n8nio/n8n
#    command: cd /usr/local/lib/node_modules/n8n && npm install --save @hashgraph/sdk && n8n start
    build:
      context: .
      dockerfile: Dockerfile
    restart: always
    ports:
      - 5678:5678
    environment:
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - NODE_FUNCTION_ALLOW_EXTERNAL=*
    volumes:
      - n8n_data:/home/node/.n8n
      - ${DATA_FOLDER}/local_files:/files
volumes:
  caddy_data:
    external: true
  n8n_data:
    external: true



and this is my Dockerfile

# syntax=docker/dockerfile:1

FROM n8nio/n8n:latest
USER root
WORKDIR /usr/local/lib/node_modules/n8n
RUN npm install --save @hashgraph/sdk
USER node

Also, don’t forget to run this code when you are on digital ocean:

`sudo snap refresh docker --channel=latest/edge`
1 Like

I’m bookmarking my own solution for myself lol

Hey @bees8,

We have similar examples on the forum, You could also use the below which will achieve the same thing.

FROM n8nio/n8n:latest
USER root
RUN npm install -g @hashgraph/sdk
USER node
1 Like

I’m pretty sure I scoured the forum finding similar cases - I think I did find one (not more, maybe I used the wrong keywords) that helped me get here.

With the code for the Dockerfile you mention in your message, would that be the only thing to be changed? Or do you also need to make the adjustments I made in the docker-compose.yml file?

Thanks!

Just replaced the Dockerfile with your piece, you’re right (of course lol) that works as well :slight_smile:

1 Like

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