Installing phaser in a project folder: multiple node_modules folders question

Hi,

I have a folder with all my projects. Every time I start a new project in a new subfolder I am installing phaser inside using npm install phaser. This results in creating new node_modules 60MB+ subfolder.
I know there is a npm flag -g when installing, but when I install phaser globally I don’t see IntelliSense hints.
Is there a way to ‘install’ the node_modules folder only once and point to it in the project instead of having it in every project subfolder?

Thnaks.
Greg.

Don’t install globally.

You can install phaser once into your projects folder, then from a subfolder (project) do

npm install ../node_modules/phaser

Thank you for your answear, but it still doesn’t work.
Here are the steps I’m taking:

cd projects
npm install phaser

output:

npm WARN saveError ENOENT: no such file or directory, open 'D:\projects\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 'D:\projects\package.json'
npm WARN projects No description
npm WARN projects No repository field.
npm WARN projects No README data
npm WARN projects No license field.

+ phaser@3.55.2
added 6 packages from 4 contributors and audited 6 packages in 2.317s
found 0 vulnerabilities

The projects/node_modules is created and it is ~61MB. There is also new file package-lock.json created.

Next steps:
cd project_01
npm install ../node_modules/phaser

output:

npm WARN saveError ENOENT: no such file or directory, open 'D:\projects\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'D:\projects\package.json'
npm WARN projects No description
npm WARN projects No repository field.
npm WARN projects No README data
npm WARN projects No license field.

+ phaser@3.55.2
updated 1 package and audited 8 packages in 0.627s
found 0 vulnerabilities

now the projects/node_modules is only 97kB and the projects/node_modules/phaser directory is empty (!?)
nothing changed in the project_01 and IntelliSense is not working :frowning:

Greg.

cd projects
npm init -y
npm install phaser --omit=dev

mkdir newproject
cd newproject
npm init -y
npm install ../node_modules/phaser

Thanks,

It works, but the biggest disadvantage of this solution is that it creates JUNCTION link in “newproject” folder to node_modules/phaser in “projects”, and JUNCTION links are absolute not relative. So copy the projects directory to other disk will break the links :frowning:

I guess that’s an npm thing.

You can go back to separate installs but use --omit=dev, that will be a little smaller.

Thanks again for your answer!

Do you mind if I ask what’s your approach? How do you structure directory tree, do you install phaser to every new project subdirectory?

Is it a problem that it is a junction? I’m sucessfully using a specific build of phaser by adding this to my package.json.

“phaser”: “file:…/…/repos/phaser”,

That creates a junction in my node_modules folder that points to this specific build.

I install Phaser separately in each project, yes.

as I mentioned before, those junctions paths are absolute, so if you copy the whole projects folder to another destination, all the node_modules links are broken and IntelliSense in VSCode stops working.

Here is a repo with multiple project folders + single node_modules.

Pass environment variables to webpack’s config file, and set these environment variables in a shell script for each project. i.e. Running packing tool with different setting for each project.