"File URL path must be absolute" on Windows
See original GitHub issue- Operating System: Windows
- Node Version: 13.*
- NPM Version: yarn 1.21.1 (does not matter)
- webpack Version: 4.*
- source-map-loader Version: 1.0.0
Problem description (actual behavior)
On Windows, cryptic warnings are emitted, saying:
WARNING in d:/my/library/dist/index.js Module Warning (from …/node_modules/source-map-loader/dist/cjs.js): File URL path must be absolute @ ./myProgram.js 8:19-42
Expected Behavior
No warning. Does not happen on Mac.
How to reproduce?
No way to easily produce a minimal example of this problem, since the given warning is too cryptic.
First Analysis
Step 1
I found out that the error message indicates one of two possible problems:
- Incorrect/unrecognized file/path for path/file conversion (as seen here)
- An incorrect file URL on Windows, as explained in node documentation (here):
On Windows, file: URLs with a host name convert to UNC paths, while file: URLs with drive letters convert to local absolute paths. file: URLs without a host name nor a drive letter will result in a throw
Step 2: Debugging source-map-loader
I went into dist/index.js
and supplemented the two calls to this.emitWarning(error)
with console.error(error)
. After snooping around a bit more, I found that this makes the problem entirely visible:
I added console.error('fetchFromUrl failed at',
>>${source}<<, ':\n', error);
to the catch
block around line 93 of the original source (NOTE: the source
variable apparently is the url to the sourcemapped file); yielding error messages like this:
fetchFromUrl failed at >>file:///webpack/universalModuleDefinition<< : TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute at getPathFromURLWin32 (internal/url.js:1310:13) at Object.fileURLToPath (internal/url.js:1342:22) at fetchFromURL (d:\my\project\node_modules\source-map-loader\dist\utils.js:151:40) at d:\my\project\node_modules\source-map-loader\dist\index.js:89:41 at Array.map (<anonymous>) at Object.loader (d:\my\project\node_modules\source-map-loader\dist\index.js:77:57)
Analysis Results
It does not seem to handle all kinds of “special” webpack urls. More invalid url examples include:
file:///webpack/universalModuleDefinition file:///webpack/bootstrap file:///external “colors/safe” file:///external “core-js/modules/es.array.concat” file:///external “lodash/isObject” file:///external “core-js/modules/web.timers”
and many more…
Also, possibly related to the fact that the imported library is umd
?
Solutions?
Not sure what to do here. But getting rid of those annoying warnings would be a great start (as I am generally not too concerned about source maps to these sorts of files to begin with).
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
👋 @evilebottnawi! Same issue here. I created a reproducible test-repo. https://github.com/icatalina/source-map-loader-116
Just clone it and:
and you can see the errors:
Thanks!