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

    How can I use npm install after deploying an app?

    App Packaging & Development
    5
    6
    318
    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.
    • M
      msbt App Dev last edited by

      I'm working on strapi and ran into an issue when installing plugins from the marketplace. This is running on node and plugins also run node commands. The problem: node_modules is in a read only location /app/pkg/app/node_modules, so the installation fails for obvious reasons.

      I couldn't find an app which does that, any pointers on how to overcome that? (other than moving everything to /app/data)

      mehdi murgero 2 Replies Last reply Reply Quote 0
      • mehdi
        mehdi App Dev @msbt last edited by

        @msbt There is no way to overcome that. It's by design. The app's code cannot be changed after build. The only work-around, like you said, would be to move to /app/data. Not necessarily "everything". You only have to symlink to /app/data the few paths which should still be writable after install

        1 Reply Last reply Reply Quote 0
        • M
          msbt App Dev last edited by

          Thanks @mehdi, was afraid that was the case. I guess it's easier to just install the few available plugins and go from there 😄

          1 Reply Last reply Reply Quote 0
          • nebulon
            nebulon Staff last edited by

            Yes that is an unfortunate situation, but if possible either first package without custom plugin support or maybe there is a way to have a secondary folder for plugins to be used.

            Generally for the app itself, if that is going to be installed during startup with npm/yarn, this is not really acceptable since the app itself then may or may not differ from instance to instance, depending on how strictly the project has locked dependency versions or worse npm might fail intermittedly.

            1 Reply Last reply Reply Quote 0
            • murgero
              murgero App Dev @msbt last edited by murgero

              @msbt

              As @mehdi explained, symlinking is probably your best bet. If you know the directory where the node plugins/packages will go, symlink that dir pre-build:

              cd /app/data
              mkdir node_modules
              ln -s /app/data/node_modules /app/code/node_modules
              

              Please take note, I am not using trailing "/" here as that has been known to cause weird issues in the past for me. The above will create a symlink in /app/code that is read-write so npm install should work (you will get cache errors since /root is not writable (or where ever npm detects it's home dir to be) but cache is not needed for npm.

              This should only be done once though either during the build (if module license allows) or during the first startup. Otherwise as @nebulon explains - instance to instance code may break (like if a module was updated in a later version of the app.)

              --
              https://urgero.org
              ~ Professional Nerd. Freelance Programmer. ~
              Matrix: @murgero:urgero.org

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

                @msbt I faced a similar issue with node-red. While I haven't tried it yet, I think what we want is to set NODE_PATH. See https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders . I guess we set NODE_PATH=/app/data/custom-modules or something ?

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