Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


    Cloudron Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular

    Solved Using handlebars.js

    N8N
    6
    17
    962
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jeau
      jeau App Dev last edited by

      I would like activate handelbars (an extension to the Mustache templating language) for Function-nodes so I've had this line in /app/data/.env

      export NODE_FUNCTION_ALLOW_EXTERNAL=handlebars
      

      but, it doesn't work when I execute my workflow, I have this error

      "Cannot find module 'handlebars'"
      
      nebulon 1 Reply Last reply Reply Quote 0
      • nebulon
        nebulon Staff @jeau last edited by

        @jeau I have to check in the package, but looks like we could add the required handlebars node module then in the package directly to get it supported if this is a common thing in n8n

        1 Reply Last reply Reply Quote 1
        • girish
          girish Staff last edited by

          The package already has N8N_CUSTOM_EXTENSIONS="/app/data/custom" though I don't know if this means that a user can npm install handlebars in that directory and use it. Maybe @BrutalBirdie knows.

          BrutalBirdie 1 Reply Last reply Reply Quote 1
          • BrutalBirdie
            BrutalBirdie Staff @girish last edited by

            @girish Got no clue either šŸ˜„
            Will have to take a look at it.

            Like my work? Consider donating a beer šŸ» Cheers!

            girish 1 Reply Last reply Reply Quote 1
            • girish
              girish Staff @BrutalBirdie last edited by

              @brutalbirdie looks like N8N_CUSTOM_EXTENSIONS is for custom nodes - https://docs.n8n.io/getting-started/installation/advanced/configuration.html#examples and not for custom node modules

              jeau 1 Reply Last reply Reply Quote 1
              • jeau
                jeau App Dev @girish last edited by

                thanks to all, I am a newbe with n8n

                @girish @BrutalBirdie this doc indicate that for security reasons, importing modules is restricted by default in the Function-Nodes and that it is possible to lift that restriction by setting the following environment variables:

                • NODE_FUNCTION_ALLOW_BUILTIN: For builtin modules
                • NODE_FUNCTION_ALLOW_EXTERNAL: For external modules sourced from n8n/node_modules directory

                So I created a node_modules directory in /app/data/ and installed in it the module handlebars with the command npm install handlebars but it doesn't work. I also tried in /app/data/.n8n directory with the same result.

                girish 1 Reply Last reply Reply Quote 0
                • girish
                  girish Staff @jeau last edited by

                  @jeau I think the module has to be installed in the docker image itself. Is there a way to not use handlebars? Just curious why it's needed. Maybe we can add it to the n8n image itself.

                  jeau 1 Reply Last reply Reply Quote 0
                  • jeau
                    jeau App Dev @girish last edited by jeau

                    @girish you can read this discussion https://community.n8n.io/t/text-templating-node/1965

                    handelbars is a template system to facilitate the creation of html document pages, https://handlebarsjs.com/

                    in my case, I want to get information from baserow tables and use n8n to generate reports and send them by mails

                    girish 1 Reply Last reply Reply Quote 0
                    • girish
                      girish Staff @jeau last edited by

                      @jeau there is a env var NODE_PATH that tells node where to find additional node modules. So, you can set the variable in /app/data/env like NODE_PATH=/app/data/modules and then in Web Terminal:

                      mkdir /app/data/modules
                      cd /app/data/modules
                      npm install handlebars
                      

                      Restart the app afterwards.

                      jeau 1 Reply Last reply Reply Quote 2
                      • jeau
                        jeau App Dev @girish last edited by

                        @girish thanks, however I have this errors after passing the command npm install handlebars

                        npm ERR! code EROFS
                        npm ERR! syscall open
                        npm ERR! path /root/.npm/_cacache/tmp/2122bb8f
                        npm ERR! errno -30
                        npm ERR! rofs EROFS: read-only file system, open '/root/.npm/_cacache/tmp/2122bb8f'
                        npm ERR! rofs Often virtualized file systems, or other file systems
                        npm ERR! rofs that don't support symlinks, give this error.
                        

                        I tried npm install --prefix /app/data/modules handlebars but the result was the same

                        however, I have already successfully installed handelbars before, but I forgot how to do it šŸ˜ž

                        robi girish 2 Replies Last reply Reply Quote 0
                        • robi
                          robi @jeau last edited by

                          This post is deleted!
                          1 Reply Last reply Reply Quote 0
                          • girish
                            girish Staff @jeau last edited by

                            @jeau I can fix that . Can you try npm install handlebars --cache /tmp/foo in the meantime ?

                            jeau 1 Reply Last reply Reply Quote 0
                            • jeau
                              jeau App Dev @girish last edited by

                              @girish I went back to a fresh installation, because I had not checked the changes of the recent updates. This fix allows me to install handelbars. But it still doesn't work, I still get the message Cannot find module 'handlebars' with this example.

                              My session:

                              root@XYZ:/app/data# vi env
                              root@XYZ:/app/data# cat env
                              # Set the logging level to 'debug'
                              export EXECUTIONS_DATA_SAVE_MANUAL_EXECUTIONS=true
                              export EXECUTIONS_DATA_SAVE_ON_ERROR=all
                              export EXECUTIONS_DATA_SAVE_ON_SUCCESS=all
                              export N8N_LOG_LEVEL=info
                              export NODE_PATH=/app/data/modules
                              export NODE_FUNCTION_ALLOW_EXTERNAL=handlebars
                              root@XYZ:/app/data# mkdir modules
                              root@XYZ:/app/data# cd /app/data/modules
                              root@XYZ:/app/data/modules# npm install handlebars --cache /tmp/foo
                              npm WARN saveError ENOENT: no such file or directory, open '/app/data/modules/package.json'
                              npm notice created a lockfile as package-lock.json. You should commit this file.
                              npm WARN enoent ENOENT: no such file or directory, open '/app/data/modules/package.json'
                              npm WARN modules No description
                              npm WARN modules No repository field.
                              npm WARN modules No README data
                              npm WARN modules No license field.
                              
                              + handlebars@4.7.7
                              added 6 packages from 39 contributors and audited 6 packages in 0.834s
                              found 0 vulnerabilities
                              
                              ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
                              │              npm update check failed              │
                              │        Try running with sudo or get access        │
                              │       to the local update config store via        │
                              │ sudo chown -R $USER:$(id -gn $USER) /root/.config │
                              ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
                              root@XYZ:/app/data/modules# ls -al
                              total 16
                              drwxr-xr-x 3 root     root     4096 Oct  9 16:25 .
                              drwxr-xr-x 8 cloudron cloudron 4096 Oct  9 16:23 ..
                              drwxr-xr-x 9 root     root     4096 Oct  9 16:25 node_modules
                              -rw-r--r-- 1 root     root     1711 Oct  9 16:25 package-lock.json
                              root@XYZ:/app/data/modules# ls -al node_modules/
                              total 36
                              drwxr-xr-x 9 root root 4096 Oct  9 16:25 .
                              drwxr-xr-x 3 root root 4096 Oct  9 16:25 ..
                              drwxr-xr-x 2 root root 4096 Oct  9 16:25 .bin
                              drwxr-xr-x 6 root root 4096 Oct  9 16:25 handlebars
                              drwxr-xr-x 4 root root 4096 Oct  9 16:25 minimist
                              drwxr-xr-x 2 root root 4096 Oct  9 16:25 neo-async
                              drwxr-xr-x 4 root root 4096 Oct  9 16:25 source-map
                              drwxr-xr-x 5 root root 4096 Oct  9 16:25 uglify-js
                              drwxr-xr-x 4 root root 4096 Oct  9 16:25 wordwrap
                              root@XYZ:/app/data/modules#
                              
                              girish 1 Reply Last reply Reply Quote 0
                              • girish
                                girish Staff @jeau last edited by

                                @jeau I have fixed the package to support this. Please try https://docs.cloudron.io/apps/n8n/#custom-node-modules with the latest package 1.16.0

                                jeau rmdes 2 Replies Last reply Reply Quote 1
                                • jeau
                                  jeau App Dev @girish last edited by

                                  @girish great thank's, it works šŸ‘

                                  S 1 Reply Last reply Reply Quote 1
                                  • rmdes
                                    rmdes @girish last edited by

                                    @girish Two questions:

                                    Do I understand correctly that this is the only way to install external modules ?

                                    Is there anything that need to be done (beside app restart) after adding the line in the env file?

                                    girish 1 Reply Last reply Reply Quote 0
                                    • girish
                                      girish Staff @rmdes last edited by

                                      @rmdes right, if you want external modules, we have to fix the package. The modules are hardcoded in the Dockerfile.

                                      1 Reply Last reply Reply Quote 1
                                      • First post
                                        Last post
                                      Powered by NodeBB