Skip to content

Commit

Permalink
fix #556: guard "ProbeResolvePackageAsRelative"
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Nov 24, 2020
1 parent 102c1f7 commit a05d6ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## Unreleased

* Fix a concurrency bug caused by an error message change ([#556](https://github.com/evanw/esbuild/issues/556))

An improvement to the error message for path resolution was introduced in version 0.8.12. It detects when a relative path is being interpreted as a package path because you forgot to start the path with `./`:

```
> src/posts/index.js: error: Could not resolve "PostCreate" (use "./PostCreate" to import "src/posts/PostCreate.js")
2 │ import PostCreate from 'PostCreate';
╵ ~~~~~~~~~~~~
```
This is implemented by re-running path resolution for package path resolution failures as a relative path instead. Unfortunately, this second path resolution operation wasn't guarded by a mutex and could result in concurrency bugs. This issue only occurs when path resolution fails. It is fixed in this release.
## 0.8.13
* Assigning to a `const` symbol is now an error when bundling
Expand Down
4 changes: 4 additions & 0 deletions internal/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ func (r *resolver) ResolveAbs(absPath string) *ResolveResult {

func (r *resolver) ProbeResolvePackageAsRelative(sourceDir string, importPath string, kind ast.ImportKind) *ResolveResult {
absPath := r.fs.Join(sourceDir, importPath)

r.mutex.Lock()
defer r.mutex.Unlock()

if pair, ok := r.loadAsFileOrDirectory(absPath, kind); ok {
return r.finalizeResolve(ResolveResult{PathPair: pair})
}
Expand Down

0 comments on commit a05d6ed

Please sign in to comment.