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

Most upvoted comments

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.

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

$ parcel watch index.html
🚨  /c/Projekte/forks/absentees-parcel-test/index.html: 
Cannot resolve dependency '/c/Projekte/forks/absentees-parcel-test/src/css/main.scss'
 at '/c/Projekte/forks/absentees-parcel-test/src/css/main.scss'
 at Resolver.resolve (/c/Projekte/forks/absentees-parcel-test/node_modules/parcel-bundler/src/Resolver.js:69:17)

https://github.com/chocolateboy/parcel-test

$ parcel watch index.html
🚨  /c/Projekte/forks/chocolateboy-parcel-test/index.html: 
Cannot resolve dependency '/c/Projekte/forks/chocolateboy-parcel-test/src/js/index.js' 
  at '/c/Projekte/forks/chocolateboy-parcel-test/src/js/index.js'
  at Resolver.resolve (/c/Projekte/forks/chocolateboy-parcel-test/node_modules/parcel-bundler/src/Resolver.js:69:17)

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.

$ cd out
$ parcel build index.html

@parcel/core: Failed to resolve
'/_next/static/chunks/polyfills-5cd94c89d3acac5f.js' from
'./out/index.html'

@parcel/resolver-default: Cannot load file
'../_next/static/chunks/polyfills-5cd94c89d3acac5f.js' in
'./out'.

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 you index.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’

1 | import {Player} from ‘./player’ | ^ 2 | 3 | export class Game { 4 | constructor (cards) {

can you explain why there are different paths?

I’ve updated the stack traces to reflect the error from the minimal test case.