You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Vite in a real-world project with many NPM dependencies that are not all pre-bundled during Vite server start, a race condition may occur when the later pre-bundling coincides with a not yet completed transformRequest() to an early pre-bundled dependency, which in turn may cause a "Failed to load source map for ..." warning.
It looks like when Vite starts pre-bundling, it cleans the cache folder and then runs esbuild. However, because esbuild is run asynchronously (proof), there is a possibility that the cache folder will be empty while esbuild is not run yet. This is a breeding ground for race conditions.
For instance, if this coincides with a stale HTTP request (or an internal call of transformRequest) currently paused on async fs.readFile, then once the source code is returned, it turns out that the corresponding source map file doesn't exist (the cache is empty) which subsequently causes a "Failed to load source map for..." warning. Here is the related fragment of code:
logger.warn(`Failed to load source map for ${url}.`,{
timestamp: true
})
}
It is not a critical issue as everything is alright after a full reload. However, when the case reproduces for many requests, many irrelevant warnings will be shown which looks like something is fundamentally broken about source maps. We could see that from time to time in our Vaadin projects:
Pre-bundling dependencies:
construct-style-sheets-polyfill
@vaadin/router
@vaadin/app-layout
@vaadin/vaadin-lumo-styles
@vaadin/tabs
(...and 55 more)
(this will be run only when your dependencies or config have changed)
vite v2.8.0-beta.2 dev server running at:
> Local: http://localhost:57720/VAADIN/
> Network: use `--host` to expose
ready in 3502ms.
Started Vite. Time: 3903ms
[vite] new dependencies found: lit/directives/class-map.js, @vaadin/icon, updating...
[vite] Failed to load source map for /@fs/Users/vursen/dev/vaadin/start/node_modules/.vite/@adobe_lit-mobx.js?v=a770d581.
[vite] Failed to load source map for /@fs/Users/vursen/dev/vaadin/start/node_modules/.vite/@vaadin_form.js?v=a770d581
[vite] Failed to load source map for /@fs/Users/vursen/dev/vaadin/start/node_modules/.vite/@vaadin_tabs.js?v=a770d581
[vite] Failed to load source map for /@fs/Users/vursen/dev/vaadin/start/node_modules/.vite/chunk-FIUHFD.js?v=a770d581
[vite] Failed to load source map for /@fs/Users/vursen/dev/vaadin/start/node_modules/.vite/chunk-JDFKUF.js?v=a770d581
[vite] Failed to load source map for /@fs/Users/vursen/dev/vaadin/start/node_modules/.vite/chunk-LSOIUE.js?v=a770d581
In my reproduction example, I had to patch Vite so that it simulates an event loop delay before reading source maps as otherwise, it is very tricky to catch the issue with few NPM dependencies (= not many transformRequest() calls).
git co race-condition-reproduction
cd packages/race-condition-reproduction
pnpm install
pnpm run serve – this builds and starts a Vite server
Open http://localhost:3000
Click the "Reproduce" button
See the "Failed to load source map" warning in Vite output
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
vursen
changed the title
"Failed to load source map" warning sometimes is shown because of a race condition
"Failed to load source map" warnings are shown because of a race condition
Jan 16, 2022
hi, I also meet a similar problem like this, when will this pr be merged ? thanks~
vursen
changed the title
"Failed to load source map" warnings are shown because of a race condition
"Failed to load source map" warnings appear because of a race condition
Feb 14, 2022
Describe the bug
When using Vite in a real-world project with many NPM dependencies that are not all pre-bundled during Vite server start, a race condition may occur when the later pre-bundling coincides with a not yet completed
transformRequest()
to an early pre-bundled dependency, which in turn may cause a "Failed to load source map for ..." warning.It looks like when Vite starts pre-bundling, it cleans the cache folder and then runs esbuild. However, because esbuild is run asynchronously (proof), there is a possibility that the cache folder will be empty while esbuild is not run yet. This is a breeding ground for race conditions.
For instance, if this coincides with a stale HTTP request (or an internal call of
transformRequest
) currently paused on asyncfs.readFile
, then once the source code is returned, it turns out that the corresponding source map file doesn't exist (the cache is empty) which subsequently causes a "Failed to load source map for..." warning. Here is the related fragment of code:vite/packages/vite/src/node/server/transformRequest.ts
Lines 106 to 126 in f346d89
It is not a critical issue as everything is alright after a full reload. However, when the case reproduces for many requests, many irrelevant warnings will be shown which looks like something is fundamentally broken about source maps. We could see that from time to time in our Vaadin projects:
Reproduction
Diff: main...vursen:race-condition-reproduction
Branch: https://github.com/vursen/vite/tree/race-condition-reproduction
In my reproduction example, I had to patch Vite so that it simulates an event loop delay before reading source maps as otherwise, it is very tricky to catch the issue with few NPM dependencies (= not many
transformRequest()
calls).git co race-condition-reproduction
cd packages/race-condition-reproduction
pnpm install
pnpm run serve
– this builds and starts a Vite serverhttp://localhost:3000
System Info
Used Package Manager
npm
Logs
Validations
The text was updated successfully, but these errors were encountered: