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

pnpm does not sync new files in local path dependencies #5381

Closed
xiaohk opened this issue Sep 21, 2022 · 6 comments · Fixed by #6623
Closed

pnpm does not sync new files in local path dependencies #5381

xiaohk opened this issue Sep 21, 2022 · 6 comments · Fixed by #6623

Comments

@xiaohk
Copy link
Sponsor

xiaohk commented Sep 21, 2022

pnpm version: 7.9.3

Code to reproduce the issue:

For example, we have the following file structure:

./
├── app
│   ├── node_modules
│   │   └── awesome -> .pnpm/file+..+pkg/node_modules/pkg
│   ├── package.json
│   └── pnpm-lock.yaml
└── pkg
    ├── bin
    └── text.txt

We have a local dependency in ./app/package.json, and ./app is initialized by pnpm run install.

"dependencies": {
  "awesome": "file:../pkg"
}

Next, we create a new file in ./pkg

echo "hiya" > ./pkg/text2.txt

Then, text2.txt is in ./pkg but not in ./app/node_modules/awesome 😥

.
├── app
│   ├── node_modules
│   │   └── awesome -> .pnpm/file+..+pkg/node_modules/pkg
│   ├── package.json
│   └── pnpm-lock.yaml
└── pkg
    ├── bin
    ├── text.txt
    └── text2.txt

Expected behavior:

I expect to see text2.txt appear in ./app/node_modules/awesome or in app/node_modules/.pnpm/file+..+pkg/node_modules/pkg

Actual behavior:

There is no text2.txt in ./app/node_modules/awesome or in app/node_modules/.pnpm/file+..+pkg/node_modules/pkg

Additional information:

Interestingly, changes to existing files are synced between ./pkg and ./app/node_modules/awesome. For example:

# Before editing
$ md5 ./pkg/text.txt
MD5 (./pkg/text.txt) = 919d117956d3135c4c683ff021352f5c
$ md5 ./app/node_modules/awesome/text.txt
MD5 (./app/node_modules/awesome/text.txt) = 919d117956d3135c4c683ff021352f5c

$ echo "oh boy" >> ./pkg/text.txt

# After editing
$ md5 ./pkg/text.txt
MD5 (./pkg/text.txt) = 6636c55e0cda2b473c75da3ff00edd52
$ md5 ./app/node_modules/awesome/text.txt
MD5 (./app/node_modules/awesome/text.txt) = 6636c55e0cda2b473c75da3ff00edd52
  • node -v prints: v16.17.0
  • Windows, macOS, or Linux?: macOS
@xiaohk xiaohk changed the title PNPM does not sync new files in local path dependencies pnpm does not sync new files in local path dependencies Sep 21, 2022
@ajmeese7
Copy link

Struggling with this same problem right now, I tried the injected solution from #3102 but it hasn't made a difference. This is a huge pain when I am trying to update a local library and test it in a different project.

@await-ovo
Copy link
Member

await-ovo commented Dec 12, 2022

It seems that if we install a local dependency using the file: protocol, it will create a hard link between the local file and the node_modules/.pnpm store, since hard links are not allowed for directories. So it can't get auto updated in node_modules when a new file added in local dependency.

But Pnpm also supports the link: protocol, which should work well when adding new files or updating existing ones.

Also, I found that even if we run pnpm update pkg to update the file: protocol for local dependency, it doesn't update to the latest files too. I'm not sure if this is a bug and may need to ask @zkochan to help look at this issue ~

@joelmoss
Copy link

I had issues with the link: protocol, so have been using file: instead, but I've now come across this. I cannot seem to find a way to update a file: dependency. update does not touch it at all.

In fact, changes to a dependency using the file: protocol are not synced at all, even when running pnpm update mypackage.

@await-ovo
Copy link
Member

I had issues with the link: protocol, so have been using file: instead, but I've now come across this. I cannot seem to find a way to update a file: dependency. update does not touch it at all.

In fact, changes to a dependency using the file: protocol are not synced at all, even when running pnpm update mypackage.

Could you share the problem of using link: protocol? or open a new issue if it is a bug, thanks.

@Mingholy
Copy link

Mingholy commented Apr 4, 2023

It seems that if we install a local dependency using the file: protocol, it will create a hard link between the local file and the node_modules/.pnpm store, since hard links are not allowed for directories. So it can't get auto updated in node_modules when a new file added in local dependency.

But Pnpm also supports the link: protocol, which should work well when adding new files or updating existing ones.

Also, I found that even if we run pnpm update pkg to update the file: protocol for local dependency, it doesn't update to the latest files too. I'm not sure if this is a bug and may need to ask @zkochan to help look at this issue ~

Seems like using pnpm update pkg --force or deleting the file+pkg... directory in node_modules/.pnpm will make pnpm be able to pick the modified pkg (maybe from the store).

It makes me quite confused when the post-install log notices me everytime:

dependencies:
+ some-local-pkg 1.0.0+[the latest version hash]

However when I use pnpm why --json some-local-pkg to get the real installation path and inspect the package.json in it, I find the version remains using a previous version hash, no matter how many updates has been made to the package.

@joelmoss
Copy link

joelmoss commented Apr 4, 2023

I have to remove it from the package.json, run pnpm i, then add it back to the package.json and run pnpm i again 😖

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

Successfully merging a pull request may close this issue.

5 participants