-
-
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
Simple tilde resolution not working for me #2813
Comments
What is the expected behaviour here? Do we want Think the relevant code is here parcel/packages/core/parcel-bundler/src/Resolver.js Lines 128 to 143 in c3921cb
|
That difference isn't ideal though |
I've looked a bit more into it and looks like the behavior is expected?
parcel/packages/core/parcel-bundler/src/Resolver.js Lines 128 to 135 in c3921cb
On an unrelated note, line 133 seems suspicous to me that it could result in another issue (in a much more obscure case though where package root has priority, but I haven't verified this). |
The code does appear like it's set up how it's supposed to be, but
|
Just to add to the above comments, I find myself building modules that are nested in several folders like Now if I import But it resolves to The doc states:
But the code states:
They are both very different behaviors. I wonder what is the use case for the latter... |
I have the same issue on OSX and I'm a little bit confused as to how it should work. The way OP describes it was in line with my intuition, but the documentation and code comments are IMO unclear. Specifically the definition of
What exactly is module root and what if my project is not in node_modules, e.g. it's an application in
and this: parcel/packages/core/parcel-bundler/src/utils/getRootDir.js Lines 3 to 29 in 161cd27
Does it really have to be that complicated? Couldn't tilde just resolve to the working directory or it's nearest ancestor that contains For reference, there is also this comment from @mischnic: #2857 (comment) . It explains the intended tilde resolution mechanism very clearly. The problem is that currently it does not work that way. In the mean time I use the following workaround: <link href = "/../node_modules/some-module/some-file.css" /> It seems to be working from anywhere inside |
Hello, just to mention that I also had to use
|
That was for that simple structure, now in other complex project structure I'm struggling with importing some css in a scss.
The entry file is located in and the import is resolving to I think that it should be |
Same issue, ~ seems to be resolving to the entry root, rendering it pretty much useless. |
Hey y'all, here's another reproduction repo for anyone who wants to quickly see this bug in action: |
In my case (MacOS) tilde resolves to... nothing really. It's just taken literally:
Adding I've resorted to using the full relative path:
|
This is still broken. For some reason, parcel tries to resolve |
|
I don't think this is getting fixed since all the focus is on Parcel 2. |
@YassienW this is broken in Parcel 2 |
@mjgerace pretty sure this works perfectly in Parcel 2. What exactly is broken about it? |
@DeMoorJasper it resolves to entry-pont directory as root instead of the package.json (or node_modules) parent directory as root. I can upload an example project/provide more details when out of work, if you'd like. |
Pretty sure #3141 fixed that |
@DeMoorJasper I am on the absolute latest version, but I can see when I get home and give you more information. |
Still not working for me in latest version (alpha 2.3). TS compiles fine, Visual Studio autocompletes fine, parcel says path doesn't exist. tsconfig:
Folder structure:
Command: Error: I also get I also have to note that in Parcel v1 this worked as expected. |
Parcel 2 is broken with respect to TypeScript tilde paths. In the Parcel docs it tells us to use
And this from the gist:
No Apparently Parcel 2 is using |
The problem with Parcel 1's
|
Understood. But the sane approach includes let us define what the root folder should be. Don't just pick one arbitrarily; let us have a say in it. And let us pick Don't break hundreds of lines of existing code because of some arbitrary new rule you'd like to add. Make the feature actually useful. Even better: Respect the |
Parcel 2 has support for custom resolver plugins, so even a non-core userland plugin could resolve |
All of that is typescript specific. Parcel has supported tilde resolution for literally years, and it applies the same way across all file types. TS doesn't get to dictate how all of Parcel works. As @mischnic said, Parcel 2 supports custom resolver plugins, and these can be chained. So we could easily support a |
A TypeScript resolver sounds perfect, so that would address my immediate request. Something that is linked from the TypeScript docs would be even better. Any documentation on how a resolver should work? |
WIP docs: https://parcel2-docs.now.sh/plugin-system/resolver/ default resolver plugin: https://github.com/parcel-bundler/parcel/blob/f65aa4c53ab130debfc88f4628eb001f52fb5f63/packages/resolvers/default/src/DefaultResolver.js default resolver implementation: https://github.com/parcel-bundler/parcel/blob/f65aa4c53ab130debfc88f4628eb001f52fb5f63/packages/utils/node-resolver-core/src/NodeResolver.js
Sure |
Merging this into #202. The original issue post and the most +1'ed comment say
which is already the case in Parcel 2. |
For me the probem were assets. I managed to resolve the issue by adding a symlink to the static folder. Take this (simplified) structure for example:
In index.html I had the option to do this: <source src="../../../static/media/videos/video.mp4" type="video/mp4" /> which I didn't like much. So I added a symlink to the static folder inside the $ ln -sfn ../../../static static Now the structure is:
and I can use: <source src="~static/media/videos/video.mp4" type="video/mp4" /> Not ideal but a lot closer to the intended use of the ~. At least the way I initially understood it. Note: the tilde isn't really necessary of course, but it reminds me of the special status of the symlinked |
An alternative to that symlink is using Like the In your case, |
Oh! Gotta try that! That's of course a lot more elegant. Thanks! |
Was this issue resolved? If code is within
It works but is kind of ugly. |
Needing to add It should take the root from the TypeScript config With Vite it all works if you import the |
Thanks I'll check out vite! |
🐛 bug report
Simple tilde paths as described under getting started don't seem to be resolving.
🤔 Expected Behavior
A repo of the error. My folder structure:
And both
index.html
files have:When I run
parcel folder1/index.html
it should build.😯 Current Behavior
parcel index.html
works fine butparcel folder1/index.html
returns:It seems to be treating the tilde as a relative path rather than looking for the folder containing
node_modules
.💻 Code Sample
Repository of the bug.
🌍 Your Environment
The text was updated successfully, but these errors were encountered: