Installation of strapi core (node modules) and project in separate directory

System Information
  • Strapi Version: 3,.5.3
  • Operating System: Debian 10
  • Database: MariaDB 10.3
  • Node Version: 14.16.0
  • NPM Version: 6.14.11
  • Yarn Version: 0.32+git

I am trying to install strapi and create a project, but I’d like them to be different directories. I’ll admit that I am new to working with node.

I’ve installed strapi as a software user in /opt/strapi, to make it available to all users on the system:

$ npm install --prefix=/opt/strapi/3.5.3 strapi@3.5.3 -g

and a link in /usr/local:

$ /opt/strapi/3.5.3/bin/strapi /usr/local/bin/strapi

/opt/strapi is about 75 MB

Then I create the poject as my own user in my own home:

$ strapi new myproject

It simply installs strapi again and all of the modules that already come with the system-installed node, for a total of 650 MB, in the project directory (myproject).

I also tried setting NODE_PATH to help the process find the already-installed modules:

$ export NODE_PATH=/usr/lib/node_modules/npm/node_modules:/opt/strapi/default/lib/node_modules/strapi/node_modules

… , but this made no difference. I used the Linux strace command to see that the NODE_PATH dirs clearly weren’t even referenced before the modules were all downloaded all over again.

How do have the project creation not install all of the modules it needs in the project dir?

Brian

I found this, which explains my confusion (frustration?):

I understand that this is a design choice to clamp down on module drift that leads to incompatibility problems, but

  1. it also results is heavier lifting in projects where 3rd party pieces (the modules) really should not be included in one’s own project - a local project might be a few MB tops - not 650 MB

  2. It also makes is harder to do upgrades, especially when it is important to nimbly respond to published vulnerabilities

Have these two issues been addressed somewhere that I am just not seeing?

Simple answer is don’t install the strapi cli tool globally and use the built in scripts located in the package.json.

Instead of strapi version use yarn strapi version or npm run strapi version likewise when you are creating new project, don’t use the global CLI use either yarn or npx:

  • npx create-strapi-app@latest my-project
  • yarn create strapi-app my-project