In regard to hoisting, I have this workspace structure:
root
-apps
-myApp
package.json
-packages
-myPackage
package.json
I have "react-native-reanimated": "~2.12.0" inside dependencies in both package.json of myApp and myPackage.
When hoisting, I expect to only see one react-native-reanimated folder in the root node_modules, but I see one in myApp and in one the root (by not in myPackage).
Isn't hoisting supposed to install a package (with the same version) in node_modules in the root node_modules and nowhere else?
Related
I have a project with a node_modules folder. Something unexpected happened and i had to delete my package.json and package-lock.json files.
Now i need to get my project's packages and dependencies etc.. into a new package.json file.
Unfortunately, running npm init doesn't get all packages that are in the node_modules directory.
For example, react and react-dom are installed and present in node_modules but don't get included in the generated package.json file by npm init; alongside other packages.
What can i do to make all my packages appear in package.json and also if possible in package-lock.json ?
I have repository with app and modules. Modules includes in app by package.json like:
"application-module": "file:../modules/application-module"
After yarn install that dependency added to node_modules.
I want to make module-base application. app folder reproduce root module. Other modules like admin-panel-module, account-module should be in modules folder. So, app may have node_modules inside, but also modules folder for modules. Those modules will add by git subtree from another repos. So, this way I can develop independently
Is any way to avoid adding and use local directories?
Multiple node_modules and package.json
In any node/npm project, you can have multiple package.json across your directory tree, like:
app/
package.json
node_modules
src...
account_module/
package.json
node_modules
src...
admin_module/
package.json
node_modules
src..
When you invoke yarn (or npm install ofc) on any of the children modules, the dependencies listed in their local package.json will be installed on the local node_modules folder.
So basically you can solve your issue ensuring that every children has their own package.json with their dependencies.
Still, you can place common dependencies in the root app folder. If all your projects for instance use lodash, you can place the lodash dependency in the add's package_json. After performing yarn in the app folder, the lodash package will be installed in the app's node_modules.
After that, if you:
require('lodash');
In any of the children, they will search for lodash in the app's node_modules folder if they don't find lodash in their own node_modules.
If you don't have a root node_modules, you can still declare a package.json local to any of the submodules, and they'll have their own node_modules.
So maybe you may want to avoid common dependencies at all, or maybe you want to store common dependencies in the app folder. Npm has you covered either ways.
However, if you don't want to handle common dependencies, yet are concerned about having to store a lot of duplicated packages in local machines, you may want to checkout pnpm, which is a wrapper over npm which allows to save a lot of space in local development machines.
I'm having (almost) the same issue with yarn.
I have create a package (typescript) called "test". In this package, after built, there are mainly 3 directories : dist (after built), node_modules and src.
Then I have created another package "test2" and in this package, have added "test" as a dependency "yarn add c:/.../.../test".
The package is the well installed in the node_module of test2. BUT, in "test2/node_modules/test", I can find the node_modules of test ( "test2/node_modules/test/node_modules". Why ? It increases the size of the package a lot.
In both tsconfig.json (test and test2) node_modules is excluded...
thks
I have my own NPM package in bitbucket as private repository which I installed in my main project as following:
"devDependencies": {
"my-package": "git+ssh://git#bitbucket.org/{name}/my-package.git"
}
This works like a charm, but there's a problem with the package itself. It contains a package.json with its own dependencies, but my main NPM is not installing this, it does not seem to keep in consideration what my package's package.json contains.
E.g: I am now missing packages that my own packages requires.
What can I do to make NPM always install my package packages defined in package.json?
Structure wise:
MyApp
- package.json (I run npm install on this one)
- some other php files..
- node_modules
- my-package
- package.json <-- This contains dependencies, which are not installed
Solved it, problem was that we defined our packages in the devDependencies, which should be in the dependencies.
I have a following folder structure:
- root/
- app/
- src/
- node_modules/
I published some package on npmjs and in the moment when i type in /root folder npm install my_package -S dependency my_package installs in root folder node_modules and i would like to install them in the package folder ie node_modules/my_package /node_modules
How to achieve it?
Cycles are handled using the property of node's module system that it walks up the directories looking for node_modules folders. So, at every stage, if a package is already installed in an ancestor node_modules folder, then it is not installed at the current location.
-npm docs
I'm getting unexpected behavior when using npm. For example when installing express with the command:
npm install express
I would expect that a folder named, "express" would be created in the "node_modules" directory and that it's dependencies would be installed within a "node_modules" sub-directory within this folder.
What I am seeing is that the "express" folder is being created but all of it's dependencies are being added to the root "node_modules" directory (same level as express) in my project folder and not nested within the "express" folder.
Why is this happening? (using npm v3.3.5)
It's a design change for npm#3, it deduplicates by default. See:
Flat, flat, flat!
Your dependencies will now be installed maximally flat. Insofar as is
possible, all of your dependencies, and their dependencies, and THEIR
dependencies will be installed in your project's node_modules folder with no
nesting. You'll only see modules nested underneath one another when two (or
more) modules have conflicting dependencies.
https://github.com/npm/npm/blob/ff47bc138e877835f1c0f419fea5f5672110678a/CHANGELOG.md#flat-flat-flat
https://github.com/npm/npm/issues/6912