question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"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:

  1. Incorrect/unrecognized file/path for path/file conversion (as seen here)
  2. 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:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
icatalinacommented, Jun 25, 2020

👋 @evilebottnawi! Same issue here. I created a reproducible test-repo. https://github.com/icatalina/source-map-loader-116

Just clone it and:

cd repo1
npm ci
npm start
cd ../repo2
npm ci
npm start

and you can see the errors:

image
0reactions
alexander-akaitcommented, Jun 25, 2020

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Absolute Windows paths are handled as invalid URL ... - GitHub
Windows paths are interpreted as invalid file URL. In Linux and Mac, the issue can't be reproduced. Fail await import("D:\repositories\fasti ...
Read more >
node.js TypeError: path must be absolute or specify root to res ...
The error is pretty clear, you need to specify an absolute (instead of relative) path and/or set root in the config object for...
Read more >
File path formats on Windows systems | Microsoft Learn
An absolute path to a file from the root of drive C: . A relative path from the current directory of the C:...
Read more >
Node: TypeError – path must be absolute - jbcEdge
The error states that you need to specify an absolute path instead of relative path. There are two approach to solve this: Approach...
Read more >
What is the difference between a relative and absolute path?
When linking to a page or file on your site, knowing the difference between a relative path and absolute path is helpful.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found