Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yarn add local file copy node_modules directory #1334

Open
emilebres opened this issue Oct 21, 2016 · 19 comments
Open

yarn add local file copy node_modules directory #1334

emilebres opened this issue Oct 21, 2016 · 19 comments

Comments

@emilebres
Copy link

Do you want to request a feature or report a bug?
Report a bug

What is the current behavior?
yarn add file:/path/to/child_project copy the node_modules directory into the node_modules directory of the parent project

If the current behavior is a bug, please provide the steps to reproduce.

  • Create a yarn project called child_project, add a dependency in this project (say react with yarn add react)
  • Create a yarn project called parent_project, add the child project to the parent project as a local file yarn add file:/path/to/child_project
  • In the parent project node_modules directory, check the child_project directory (ls node_modules/child_project):
    you get
node_modules
package.json
yarn.lock

What is the expected behavior?
Not sure exactly what should happen but I guess the node_modules directory should not be copied. Moreover yarn should probably read .npmignore (and .yarnignore ?) in order to copy only the necessary files.

Please mention your node.js, yarn and operating system version.
node v6.8.1
yarn v0.16.0
macOS Sierra 10.12

@mmeineke
Copy link

Also it seems, that the files property in the package.json is ignored with local and github dependencies.

@robert-may1
Copy link

If the child project is also a git repository, yarn add makes a copy of the .git folder in the parent project's node_modules/child_project. Trying to add another dependency to the parent project fails because it cannot delete the locked files in the .git folder.

@Ciantic
Copy link

Ciantic commented Dec 11, 2016

Surely what @mmeineke mentioned is a bug? Right now if you have three packages:

packages/number-one
packages/number-two
packages/number-three
(All packages have .npmignore or node_modules ignored via package.json files)

Where three depends on two, two depends on one, it installs node_modules three times, like this:

packages/number-one/yarn install -> creates node_modules
packages/number-two/yarn install -> creates node_modules containing number_one with node_modules
packages/number-three/yarn install -> creates node_modules containing number_one with node_modules , number-two with node_modules etc...

Since it replicates node_modules of each local package, you quickly get huge megalomanically big directories with several hunderds of thousands of files. (Since it replicates all node_modules).

P.S. These packages are linked using file syntax e.g. "file:../number-two".

Also I've confirmed that with npm install it works just fine, the files attribute is being followed even when the packages are linked with file:... syntax, and there are no node_modules duplication. So this must be a bug in yarn.

@xogeny
Copy link

xogeny commented Feb 2, 2017

I've run into this issue as well. Copying the node_modules directory causes the TypeScript compiler to have a fit, BTW.

@cooperka
Copy link

cooperka commented Jul 2, 2017

Confirmed still an issue with yarn install v0.27.5.

This bug causes npm start to fail in React Native libraries that include an example app (a common pattern) due to @providesModule collisions (similar to facebook/react-native#13364). One workaround is to simply install again using npm, which doesn't copy in node_modules.

Another workaround is to add a postinstall script to rm -rf node_modules/my-library/node_modules.

@robertherber
Copy link

robertherber commented Aug 1, 2017

This is a major issue I've come across in several projects now. The behaviour of copying the node_modules folder results in multiple copies of the same library being used, which in turn results in lots of weird behaviour.

Right now I'm using the same workaround as @cooperka (rm -rf node_modules/my-library/node_modules), but I don't understand the behaviour for file: installs are so different from other installs.

Also on yarn v0.27.5.

@fbartho
Copy link

fbartho commented Oct 30, 2017

I too am exhibiting this problem. This occurs when trying to import Typescript definitions like @types/react-redux when you also directly have @types/react imported.

I'm using yarn 1.2.1

$ yarn --version
1.2.1

I'm also fixing it by adding a line to our postinstall script.

@p-engelkes
Copy link

I have the same problem as explained above.

$ yarn --version
1.1.0

The problem disappears after installing the dependencies with npm.

@kevinbuhmann
Copy link

This is still happening with yarn v1.3.2.

@robertherber
Copy link

robertherber commented Jan 12, 2018

I've given up on yarn for handling this at the moment. I have a monorepo with a core component I reuse and I've added this script to package.json, and I run in on postinstall. Maybe it helps someone else:

"update-core": "rsync -av --progress ../core/ ./node_modules/my-core-module-name/ --exclude node_modules",
"postinstall": "npm run update-core",

@wonkim00
Copy link

Finally figured out that this is what's been happening to us when our devs' local builds fail for seemingly mysterious, spurious reasons. Ugh.

@AshMcConnell
Copy link

This is still a problem for us in 1.7.0

@GeeWee
Copy link

GeeWee commented Feb 14, 2019

Still a problem in 1.13.0

@alcuadrado
Copy link

I run into this issue when installing local packages with peer dependencies.

A longer explanation: I'm developing package P, which has a peer dependency PD. P is a TS project, so I need PD installed in order to compile it. I create package T to test P, install P (yarn add <path>) and PD (yarn add <package>) in T. Now I have two versions of PD, which shouldn't happen.

A workaround: Remove P's node_modules before installing it in T. This really complicates my workflow though.

yarn --version
1.13.0

@wwahammy
Copy link

Just wanted to mention this is still a problem in yarn 1.22.4.

epaew added a commit to epaew/eslint-plugin-filenames-simple that referenced this issue Nov 24, 2020
epaew added a commit to epaew/eslint-plugin-filenames-simple that referenced this issue Nov 24, 2020
epaew added a commit to epaew/eslint-plugin-filenames-simple that referenced this issue Nov 24, 2020
epaew added a commit to epaew/eslint-plugin-filenames-simple that referenced this issue Nov 24, 2020
epaew added a commit to epaew/eslint-plugin-filenames-simple that referenced this issue Nov 25, 2020
epaew added a commit to epaew/eslint-plugin-filenames-simple that referenced this issue Nov 28, 2020
epaew added a commit to epaew/eslint-plugin-filenames-simple that referenced this issue Nov 28, 2020
epaew added a commit to epaew/eslint-plugin-filenames-simple that referenced this issue Nov 28, 2020
epaew added a commit to epaew/eslint-plugin-filenames-simple that referenced this issue Nov 28, 2020
@sunnylqm
Copy link

sunnylqm commented Mar 1, 2021

Found an easy workaround:
add a preinstall script to your package:

"scripts": {
    "preinstall": "rm -rf node_modules"
  },

When developing this package, you still get every deps you need but these will be removed when installing happens in userland.

somay added a commit to DataSignInc/react-native-did-siop that referenced this issue Mar 18, 2021
@ADTC
Copy link

ADTC commented Nov 18, 2022

WTF. It's ignoring .gitignore too. This caused my React app to conk out with:

Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
(1 & 2 redacted)
3. You might have more than one copy of React in the same app

Indeed, I did. One version in my app, and another version in the package!

I suppose the preinstall script is the only good workaround right now. Also, we may need to include .git there:

  "scripts": {
    "preinstall": "rm -rf node_modules .git"
  },

Note that you need to run yarn install --force in your main application to refresh the package and run the script.

@DuncanHouston
Copy link

Still a problem with v.1.22.19.

I've used the postinstall script in the parent project, works fine.

How do I use a preinstall script on the child project? I can add it, but it doesn't run when doing "yarn add file..."

1 similar comment
@DuncanHouston
Copy link

Still a problem with v.1.22.19.

I've used the postinstall script in the parent project, works fine.

How do I use a preinstall script on the child project? I can add it, but it doesn't run when doing "yarn add file..."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests