-
-
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
Cannot resolve dependency, but file exists #1986
Comments
Here's an example of the stack traces I get for the first and second call to Good:
Bad:
The error occurs when either prefix is used — i.e. tilde (
|
Did you notice in your <script src="/index.js"></script> did you mean to write <script src="./index.js"></script> What happens if you try to import your assets relatively? (like the one above) Could you please provide a repo? |
Also I don't think this is a sass related issue like in #1555 because sass handles file paths differently (sass can use |
As of #850, absolute paths (i.e. paths starting with a slash) are supposed to be resolved against the project root, and paths starting with a tilde are supposed to resolve against the package root (i.e. the nearest Parcel (v1.7.0 and above) supports multiple module resolution strategies out of the box so you don't have to deal with endless relative paths `../../`. |
I tested both repos and both examples worked as intended. I had no errors. |
What I just noticed is, that in your issue you mention two different paths in the stacktrace:
one path starting with if that is the case, the output files should got to can you explain why there are different paths? |
I've updated the stack traces to reflect the error from the minimal test case. |
Which OS and node version? |
I can still see two different path, now:
I guess you are using your own local-linked version of
Node: 10.4.0 |
Yes. I get the same error with the stock v1.9.7 release. |
just to make sure... |
I'm not npm-linking the git version of parcel. I'm just using a symlink:
But, like I say, the same error occurs with the released version. I'm only using the git version to troubleshoot this issue. I've just installed node v10.4.0, and get the same error. Maybe it's an OS issue? |
That's weird. despite I would never symlink any npm package on my own but use |
It's the way that's recommended in the contributing guidelines (the shebang uses Thanks for your help btw 👍 |
My Ubuntu / WSL installation also fails with same errors: https://github.com/absentees/parcel-test
https://github.com/chocolateboy/parcel-test
Node: 10.4.0 |
From what I can gather (someone correct me if I'm wrong), it looks like there are (at least) two passes over each dependency:
The dependency objects produced by the first pass only contain a few fields (at least to start with) e.g.: {
name: '/home/user/build/parcel-test/src/js/index.js',
parent: '/home/user/build/parcel-test/index.html'
} Note that the name, which appears as An easy fix would be to add a field to the dependency which indicates that it has already been resolved e.g.: {
name: '/home/user/build/parcel-test/src/js/index.js',
parent: '/home/user/build/parcel-test/index.html',
resolved: true,
} But it turns out this is already supported (in a slightly different form)! The processing/bundling pass checks each dependency object's Adding that field (in {
name: '/home/user/build/parcel-test/src/js/index.js',
parent: '/home/user/build/parcel-test/index.html',
resolved: '/home/user/build/parcel-test/src/js/index.js',
} I've raised a PR for this here. Let me know if there are any issues. |
Fix "Cannot resolve dependency" errors for valid slash and tilde paths. Before: /src/js/index.js -> /home/user/my-project/src/js/index.js -> /home/user/my-project/home/user/my-project/src/js/index.js Error: Cannot resolve dependency /home/user/my-project/src/js/index.js After: /src/js/index.js -> /home/user/my-project/src/js/index.js The code already has a way for asset-handlers to signal to the bundler that a dependency has been resolved to an absolute path, but it isn't being used. fixes #1555 fixes #1986
Fix "Cannot resolve dependency" errors for valid slash and tilde paths. Before: /src/js/index.js -> /home/user/my-project/src/js/index.js -> /home/user/my-project/home/user/my-project/src/js/index.js Error: Cannot resolve dependency /home/user/my-project/src/js/index.js After: /src/js/index.js -> /home/user/my-project/src/js/index.js The code already has a way for asset-handlers to signal to the bundler that a dependency has been resolved to an absolute path, but it isn't being used. fixes #1555 fixes #1986
Fix "Cannot resolve dependency" errors for valid slash and tilde paths. Before: /src/js/index.js -> /home/user/my-project/src/js/index.js -> /home/user/my-project/home/user/my-project/src/js/index.js Error: Cannot resolve dependency /home/user/my-project/src/js/index.js After: /src/js/index.js -> /home/user/my-project/src/js/index.js The code already has a way for asset-handlers to signal to the bundler that a dependency has been resolved to an absolute path, but it isn't being used. fixes #1555 fixes #1986
This comment has been minimized.
This comment has been minimized.
issue still exists |
Yes it does. I'd suggest moving to webpack, it's a much better experience. They seem to just ignore issues in this repo and mark stuff closed that is clearly still an issue. |
This issue was closed because it was fixed (at the time). If it happens again, there might be a different cause (= new issue). |
I have the same problem Server running at http://localhost:1234
|
If it helps, note that
and run |
Program is making bold assumptions about my project structure.
It's not wrong that this is a directory inside a project, but as a CLI, the project directory should be the current working directory. I do not need Parcel confusing itself about what the root directory is. Is it looking for If you're inside |
❔ Question
i don't understand why pacel could not resolve a dependency.
when i run
parcel build index.html
i get the errorbut the file exists:
why pacel could not resolve the dependency?
🔦 Context
i debugged a little bit and it seems that pacel resolves the path as
/Users/tim/proj_/parcel-example/Users/tim/proj_/parcel-example/index.js
the function
parcel/src/Resolver.js
Line 121 in a330668
is called twice, first call
i expected this path as result, but parcel goes on and does a second call:
which will result in /Users/tim/proj_/parcel-example/Users/tim/proj_/parcel-example/index.js
💻 Code Sample
index.html
index.js
🌍 Your Environment
The text was updated successfully, but these errors were encountered: