Tiago Albineli Motta
Tiago Albineli Motta

Reputation: 139

Why npm install <folder> install different dependencies than npm install lib

I have a project1 that already depends on [email protected]

When I try to install the project2 as a lib in the project1 using npm install /my/project2/build, my package-lock.json is changed as the snipped showed bellow:

+    "projec2": {
+      "version": "file:/my/project2/build",
+      "requires": {
+        "styled-components": "4.4.1"
+      },
+      "dependencies": {1
+        "@babel/code-frame": {
+          "version": "7.16.7",
           ...
+          "requires": {
+            "@babel/highlight": "^7.16.7"
+          }
+        },
+        "@babel/generator": {
+          "version": "7.17.7",
           ...
+          "requires": {
+            "@babel/types": "^7.17.0",
+            "jsesc": "^2.5.1",
+            "source-map": "^0.5.0"
+          }
+        },
+        "@babel/helper-annotate-as-pure": {
+          "version": "7.16.7",
           ...
+          "requires": {
+            "@babel/types": "^7.16.7"
+          }

But if i publish the same project2 lib and I install it using npm install [email protected], the package-json.lock on project1 does not show the same requirements:

+    "project2": {
+      "version": "0.0.1",
       ...
+      "requires": {
+        "styled-components": "4.4.1"
+      }
+    },

I would like to make the local folder installation as same as the lib installation, without those third part dependencies.

Update:

I still have the problem installing with npm install <folder> but using npm pack combined with npm install <tarballfile> works like installing the the remote lib. I just dont know why...

Upvotes: 2

Views: 350

Answers (1)

To simulate remote lib installation locally I like to use yalc. You don't necessarily need to install it, you can run with "npx yalc publish" for example.

What "npx yalc publish" does is instead of publishing the build in npm, it will publish it in a local folder. Then when you "npx yalc add [email protected]" it will act as if the lib was downloaded from npm.

It should behave the same as publishing in unkpg and then installing it.

Upvotes: 1

Related Questions