Unexpected files when installing a local module
Do you want to request a feature or report a bug? bug
What is the current behavior? In real time it may be tens, maybe even thousands of modules. I'll give an easy example for clarity.
I have 2 local modules:
- my-module-1
- my-module-2
Both modules use Git without remote repo. my-module-1 is connected to the my-module-2 locally.
Tree my-module-1:
~$ tree my-module-1/ -L 1 -a
my-module-1/
|-- .editorconfig
|-- .git
|-- .gitattributes
|-- .gitignore
|-- .npmignore
|-- index.js
|-- lib
|-- package.json
`-- readme.md
2 directories, 7 files
.npmignore file content in the my-module-1:
# All
*
# But not
!lib/**
!readme.md
!index.js
!package.json
Tree my-module-2:
~$ tree my-module-2/ -L 1 -a
my-module-2/
|-- .git
`-- package.json
1 directory, 1 file
package.json file content in the my-module-2:
{
"private" : true,
"dependencies": {
"my-module-1": "file:../my-module-1"
}
}
When I install dependencies in my-module-2 by yarn i see tree:
~/my-module-2$ tree node_modules/my-module-1/ -L 1 -a
node_modules/my-module-1/
|-- .editorconfig
|-- .git
|-- .gitattributes
|-- .gitignore
|-- .npmignore
|-- index.js
|-- lib
|-- package.json
`-- readme.md
2 directories, 7 files
It turns out that yarn simply copies all folders and files from the my-module-1.
If the current behavior is a bug, please provide the steps to reproduce.
Install yarn by npm globally:
$ npm i -g yarn
Install dependencies in my-module-2 by yarn:
~/my-module-2$ yarn
yarn install v0.16.1
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 0.19s.
What is the expected behavior?
Like npm i.
Tree:
~/my-module-2$ tree node_modules/my-module-1/ -L 1 -a
node_modules/my-module-1/
|-- index.js
|-- lib
|-- package.json
`-- readme.md
1 directory, 3 files
As you can see, npm don't copy all files and folders, because it uses file .npmignore. Even if you are not using file .npmignore, then npm still does not copy the folder .git and uses .gitignore for ignore.
But yarn copies all. Maybe there is some kind of .yarnignore?
Please mention your node.js, yarn and operating system version.
~$ node --version
v6.9.1
~$ npm --version
3.10.8
~$ yarn --version
0.16.1
~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.1 LTS
Release: 16.04
Codename: xenial
~$ uname -a
Linux undefined 4.4.0-45-generic #49-Ubuntu SMP DATE x86_64 x86_64 x86_64 GNU/Linux
I believe that Yarn should support .npmignore file as well to ease up on the transition. Also requiring developers to actually maintain both ignore files (which would be completely identical) seems silly.
I faced with the same issue. It seems that Yarn still doesn't support .npmignore at v0.19.1.
Can this issue be fixed? As of v1.8.0, local module installs still do not respect .npmignore. For locally installing a large git repository, yarn install takes very long each time the command is run. I can provide a repro repo if that helps. Is there a known workaround? I was hoping #5979 would fix this issue, but manually applying the changes doesn't seem to help.
.npmignore not working for v1.17.3
~$ node --version
v12.10.0
~$ npm --version
6.11.3
~$ yarn --version
1.17.3
.yarnignore & .npmignore
.DS_Store
.babelrc
.browserslistrc
.editorconfig
.eslintignore
.eslintrc.js
.git
.gitignore
.npmrc
/build
/node_modules
/src
/static
webpack*
package.json conf, like this:
{
"name": "local-project",
"version": "0.0.1",
"main": "main.js",
"license": "MIT",
"files": [
"dist",
"yarn.lock",
"README.md"
]
}
Still not working for 1.22.5
Just ran into this, thanks for leaving a trail.
(Also, it means if you add a local reference to parent directory, which I was doing for CI purposes, you can end up with like a russian nesting doll situation of yourself inside yourself inside yourself).
Anyone know if this has been dealt with in any way in any Yarn, whether 2+ or 1? The project I am currently in is still using yarn 1 "classic".
Ah, this is actually a dup of #2822 which wound up with many more comments.
Seems like it is def not solved in any yarn 1. :(. I am not sure if it's solved in any yarn 2+.