-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Parcel 2 doesn't detect changes in linked dependencies. #4332
Comments
Could you create a repo with some instructions on how I'd reproduce this? Would help a lot in fixing this |
Ok, here you go: https://github.com/samuelgozi/Parcel2-issue-4332 |
@samuelgozi thanks for creating the repo, I can reproduce it pretty consistently, will try and figure out why it happens and hopefully fix it |
@DeMoorJasper Thank you! |
I develop a local npm package and experience the same issue using the |
This is because the file watcher only watches for changes in the project root. It would be somewhat hard to implement support for symlinks outside the project I think. If we implemented this in the watcher we'd need to somehow crawl the whole file system to detect symlinks in the first place which would be very slow. We could potentially do it by detecting files that resolve to symlinks as we build the asset graph and keep nodes in the request graph to track watch roots. Then we'd have to re-watch all of those on startup and invalidate each of them for changes as opposed to just the project root. |
This was actually working in parcel 1. Currently I had to revert back to parcel 1 while keeping its dependencies in parcel 2 to correctly build as module. |
This issue keeps me from migrating to v2, too. I wonder how other developers handle this workspaces issue - also considering monorepos are now en vogue. We can't possibly be alone here @ramirofages |
You guys should have a look at #6039 regarding the yarn.lock / package-lock.json files. This probably solves the issue for you too. |
That linked issue doesn't resolve this for me. I don't have a dangling yarn.lock file, just the one in my primary repository I'm working on. Linked dependency changes don't trigger a recompile, and it seems even restarting parcel and running it with |
Afaik parcel can't look outside its start context so if you want to watch all workspaces in a workspace root you'll need to start parcel in that root. Did you do that? Be extra sure to not have any lock files inside any of the workspaces. Parcel unfortunately has no warning for that and will just silently fall back to the workspace scope instead of root scope, which took a lot of lifetime from me in the past the point where I wanted to quit my job and start a lumber business :D |
I am trying to link a dependency that is located in a separate folder and repository on my machine, but installed via npm. The |
As long as the node_modules is inside the parcel start context it works. Again parcel picks its start context by probing all folders for .lock files starting with the most-inner one from your start path:
wherever a lock file is found it will not recognize changes beyond that folder. Ever. And they are not planning to change that. |
Yep I hear you, but let me be more explicit about my setup. I have: project-a/
src/ # code lives here
example/
index.html # no lockfile here, no package.json, no node_modules
package.json # here is my script "npm run example": "parcel example/index.html"
package-lock.json
node_modules/
project-b/
project-b/ # linked to ^
src/
dist/ It is the linked project-b dependency which is changing and not triggering a rebuild inside project-a when I run |
So its linked by
Edit: also to clarify, parcel doesn't watch the node_modules (since its essentially a black hole), it watches source files and triggers a reload when they change. |
If
No, it watches everything except for VCS directories and parcel/packages/core/core/src/RequestTracker.js Lines 918 to 920 in ff6b7b4
|
Okay yes it is the "Edit" there that is my problem then. The confusing thing is that this did work with parcel v1. When I would As mentioned, |
Ah cool! Didn't know that. How about symlinks then? |
@mischnic so it does appear that this is a legitimate bug and not intended behavior, then. Should |
"only files inside of that are watched" essentially ignores symlinks. This is mostly because the file watching APIs from the various OSs only fire change events for the actual parent directories and don't traverse through every symlink So So this is more of a technical limitation at the moment, as explained in #4332 (comment) and not a design decision
What do you mean? It intentionally watches node_modules so that updating dependencies and rerunning Yarn triggers a Parcel rebuild for changed files. |
I see, thanks for the explanation. I wonder if it would be possible to make an option to explicitly tell parcel about a symlinked dependency you would like to be watched, as this does seem like it would be a common use case.
I meant should |
That's not the issue. Symlinks can still resolve to locations outside Parcel's project root, which is defined to be the nearest directory with a Is there a reason not to put your lock file at the root of your repo? |
@Systemcluster - As discussed above, allowing Parcel to watch symlinks outside the project root is trickier to implement. Allowing users to specify additional paths to watch outside of Parcel's project root seems like a fair compromise - and it sounds rather easy to do. As many have mentioned, the "project root" means the folder containing the package lock file. |
This used to work without issue in V1 (parcel-bundler) just by adding a link in package.json of the main project. Any changes on the linked package caused a refresh. This has now been open for 3 years and it was something that worked flawlessly on the first version of Parcel. It's an incredibly useful feature when you're working on a library. |
Wow it really has been 3 years! Like I've said, I'd be happy to open a PR to resolve this one if I can get some feedback from the devs that it's likely to be merged. If the devs explicitly don't want this feature, I don't want to waste my time. Thoughts? @devongovett |
I for one would be really happy with a fix. I've built a script in my webapp that copies on change, not really the solutions you want |
@bminer I don't see why at least giving developers an option through a flag as you suggested would be an issue, if respecting symlinks outside the project root as before is out of the question. In our case, the package I'm working on is a dependency on more than one in-house project, and is not an integral part of any of the parent projects. It doesn't make sense to build all as "workspaces" as the parent projects have no relation between them. |
I'm getting the same issue. Building a package and I have a demo app using Parcel 2 in an folder |
I run into this issue recently, the fact that it is standing for 3 years is amazing. unfortuntly, such limitition in parcel 2 makes it less productive when working with linked dependencies. |
I agree it would be great to have this fixed. My scenario seems even simpler: some_root_dir/ where client.js imports shared.js -- When I change client.js Parcel does its thing, updates the browser and life is good. When I updated shared.js nothing happens. So to me, the file-watching issue comes down to: |
some issue, any way to solve this problem? |
@rodrigo-nexudus there is the case what we want. |
@jteppinette Thanks for your message. #4332 (comment) The best I could do at the moment. Since inside the folder, there are still their dependencies with package-lock.json. |
I personally worked around this using npm i concurrently nodemon --save-dev See
"scripts": {
"prestart": "rimraf .parcel-cache",
"start": "concurrently \"npm run watch:lib\" \"npm run link:lib && npm run start:demo\"",
"start:demo": "parcel demo/index.html --open",
"build:lib": "rollup -c rollup.config.ts --configPlugin @rollup/plugin-typescript",
"link:lib": "rimraf node_modules/my-lib && linklocal",
"watch:lib": "nodemon -e ts --watch src --exec npm run build:lib",
}, Hope that helps anyone! |
Thanks, it works for me with I've the app and, outside, I've shared js files (assets dir). app/ The dir assets is installed with And now with this config in the app/package.json and the new
The HMR is working again, like in parcel1. I mean, if I make a change in my assets js files, the app rebuild automatically. |
For those having issues, I have created a CLI-tool that can help deal with local npm packages: physical-link It's not parcel-specific, but it solves the problem of aliased packages not being watched. What it does is basically watch your package files and copy changes to the It's a handy tool when you can't have a monorepo and develop your packages as separate projects, and use them in your other projects. |
I really hoped that when I Googled this issue I would find a solution. I went off on a tangent one night writing a bunch of utilities to simplify a project, then realized it made no sense for them to belong to that project instead of being somewhere I could share with other projects. So I pulled it out into its own package... and now Parcel ignores any changes I make to it because the linked package doesn't trigger the watcher. |
Since |
This still does not work for me when I do a I am using a lerna monorepo and this is my full parcel command:
I didn't really want to setup a dev / watch command although I might now... |
Interesting. I am doing something quite similar, and it seems to work fine: |
I don't think The entire purpose if Personally, I think the original labeling of this as a bug was correct since it's a regression from Parcel 1. But even as a feature request, it's still more than valid and is not adequately satisfied by |
I agree. However, this especially noticeable when using parcel build over parcel watch. |
@bradleat - Are you saying that |
@bminer Yes. When I parcel build with the command above and have updated linked build files, they are sometimes not included in the build. I really can't figure out why it is sometimes. When watching, it will work. |
It seems like it just uses it's cached version since it doesn't detect that anything is changed. I'm constantly needing to use |
@bminer In my experience with this bug, the problem was that Parcel watching didn't follow symlinks. If watching In my case, I wasn't using I recall that I was able to bisect the origin of this bug to some refactor of how symlinks were resolved when traversing |
🐛 bug report
When working on a dependency locally by linking it, Parcel 2 doesn't detect changes and therefore doesn't rebuild. You also need to remove the cache manually in order for it to work on re-runs.
🎛 Configuration (.babelrc, package.json, cli command)
Package.json
The commands I use:
🤔 Expected Behavior
Like in version 1, Parcel should detect changes in linked dependencies, invalidate the cache and rebuild.
😯 Current Behavior
No changes are made, which require manual removal of
.parcel-cache
and then building again.🔦 Context
I use Parcel to work on npm modules often. Without detecting the changes in linked packages there is no reason for me to use parcel. In fact, it becomes painful to do so...
🌍 Your Environment
The text was updated successfully, but these errors were encountered: