parcel: Cannot resolve dependency, but file exists
❔ Question
i don’t understand why pacel could not resolve a dependency.
when i run parcel build index.html
i get the error
/Users/tim/proj_/parcel-example/index.html: Cannot resolve dependency '/Users/tim/proj_/parcel-example/index.js' at '/Users/tim/proj_/parcel-example/index.js'
but the file exists:
➜ parcel-example cat /Users/tim/proj_/parcel-example/index.js
console.log("ok");
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 https://github.com/parcel-bundler/parcel/blob/a3306688de7be54459163ae44e19c32e7a663168/src/Resolver.js#L121
is called twice, first call
this.options.rootDir
/Users/tim/proj_/parcel-example
filename.slice(1)
index.js
i expected this path as result, but parcel goes on and does a second call:
this.options.rootDir
/Users/tim/proj_/parcel-example
filename.slice(1)
Users/tim/proj_/parcel-example/index.js
which will result in /Users/tim/proj_/parcel-example/Users/tim/proj_/parcel-example/index.js
💻 Code Sample
index.html
<html>
<body>
<script src="/index.js"></script>
</body>
</html>
index.js
console.log("ok");
🌍 Your Environment
Software | Version(s) |
---|---|
Parcel | 1.9.7 |
Node | v10.9.0 |
npm | 6.2.0 |
Operating System | osx and ubuntu |
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 26 (20 by maintainers)
Commits related to this issue
- Don't resolve slash and tilde paths twice (#1993) Fix "Cannot resolve dependency" errors for valid slash and tilde paths. Before: /src/js/index.js -> /home/user/my-project/src/js/ind... — committed to parcel-bundler/parcel by chocolateboy 6 years ago
- Don't resolve slash and tilde paths twice (#1993) Fix "Cannot resolve dependency" errors for valid slash and tilde paths. Before: /src/js/index.js -> /home/user/my-project/src/js/ind... — committed to parcel-bundler/parcel by chocolateboy 6 years ago
- Don't resolve slash and tilde paths twice (#1993) Fix "Cannot resolve dependency" errors for valid slash and tilde paths. Before: /src/js/index.js -> /home/user/my-project/src/js/ind... — committed to parcel-bundler/parcel by chocolateboy 6 years ago
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).
issue still exists
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 Yarn: 1.9.4 OS: WSL (Debian 9.3) 4.4.0-17134-Microsoft running on: Windows 10 [10.0.17134.228]
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
package.json
, or what? If you’re going to ship logic like that, we need an escape hatch at the very least.If you’re inside
.
, and I feed youindex.html
and it contains a<script src="/_next/..." />
, it is startling that you would come back to me with an error./_next
is./_next
relative to.
, it’s super straightforward? I would send in a PR but if this is possible this late in the software’s lifecycle, I imagine it would be a waste of time.I have the same problem
Server running at http://localhost:1234 🚨 /home/uge/Sandbox/webgame/foracciodue/src/game.js:1:21: Cannot resolve dependency ‘./player’ at ‘/home/uge/Sandbox/webgame/foracciodue/src/player’
I’ve updated the stack traces to reflect the error from the minimal test case.