ai / size-limit

Calculate the real cost to run your JS app or lib to keep good performance. Show error in pull request if the cost exceeds the limit.
MIT License
6.48k stars 1.82k forks source link

Receive ERR_UNSUPPORTED_ESM_URL_SCHEME error on version 10 #342

Closed Kysluss closed 8 months ago

Kysluss commented 8 months ago

After updating from version 9.0.0 to 10.0.2, I get the below error when attempting to run size-limit or size-limit --why. I have made a repro project which is basically just a new react app initialized and size-limit installed.

Steps to reproduce on Windows:

  1. Clone repro
  2. Run yarn to initialize repro
  3. Run yarn build followed by yarn analyze to see that it works on v9
  4. Run yarn upgrade-interactive --latest to upgrade all the packages to latest version
  5. Run yarn build followed by yarn analyze and you will get the below error message

    ERROR Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:' at new NodeError (node:internal/errors:406:5) at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:216:11) at defaultLoad (node:internal/modules/esm/load:118:3) at ModuleLoader.load (node:internal/modules/esm/loader:396:13) at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:278:56) at new ModuleJob (node:internal/modules/esm/module_job:65:26) at #createModuleJob (node:internal/modules/esm/loader:290:17) at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:248:34) at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:229:17) at async ModuleLoader.import (node:internal/modules/esm/loader:315:23)

ai commented 8 months ago

Do you use Windows? Do you have this error on Linux (you can test on Github Actions)

Kysluss commented 8 months ago

Hello,

I am on windows. Unfortunately, I don't have access to try this on Linux. I will try on github actions, but the repo I am contributing to does not have those set up and I do not have access to set them up.

ai commented 8 months ago

Seems like we need to put pathToUrl() somewhere. We do not have this problem on Linux, because it doesn’t have disk prefix.

The main problem that I can’t reproduce the error and stacktrace doesn’t help us.

So you will need to debug Size Limit on your Windows machine. Use debugger or console.log() to find what lines are executed and where Size Limit falls.

smlkA commented 8 months ago

I confirm that this bug happened only on Windows OS. But this commit - https://github.com/ai/size-limit/commit/67a52d2b51bc49e766ef741363415898d9ec8f1f fixed the error. The reason was that on Windows argument of dynamic import was something like - _C:\Users\ASM017\Desktop\my-app\nodemodules\@size-limit\file\index.js. Now the argument is a module name and it works correctly.

Kysluss commented 8 months ago

Thank you. I confirmed this resolved the error as well.