Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absolute path matching problem for npx svench command on Windows #30

Closed
jacob-8 opened this issue May 15, 2021 · 6 comments
Closed

Absolute path matching problem for npx svench command on Windows #30

jacob-8 opened this issue May 15, 2021 · 6 comments

Comments

@jacob-8
Copy link
Contributor

jacob-8 commented May 15, 2021

When running npx svench on Windows using version 0.2.0-14, I immediately receive the error:
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'

Windows Subsystem for Linux is not an option either as it throws: error: The working directory "/mnt/c/dev/kit-svench" is not an absolute path

nodejs/node#31710 provides some context and sveltejs/vite-plugin-svelte#29 makes me think the solution will be found in wrapping the culprit url in url.pathToFileURL().

Repro: https://github.com/jwrunner/svelte-kit-svench

@jacob-8 jacob-8 changed the title Path matching problem for npx svench command on Windows Absolute path matching problem for npx svench command on Windows May 15, 2021
@jacob-8
Copy link
Contributor Author

jacob-8 commented May 15, 2021

I borrowed from sveltejs/vite-plugin-svelte@7a7f908 and tried to create a temporary patch on my machine by editing svench/cli/commands/vite/dev.js. I succeeded it getting it one step further by getting loadVite() to run but then ran into a problem with loadSvenchifiedConfig(). See my attempt at https://gist.github.com/jwrunner/adeb4b0e4f9c20d881f080e1f77b3e58

A permanent patch may belong in normalizeGlobalOptions() or neighbors in svench/cli/cli.js?

@rixo
Copy link
Owner

rixo commented May 15, 2021

Thanks for reporting.

Can you please try with version v0.2.0-20 (tagged next on npm, so something like npm i -D svench@next) and confirm you still have this error?

If you still have the problem, can you post the complete errors that you get, including stack trace (you can edit out the complete paths on your machine if you want, but the actual call stack & line numbers in Svench files is important).

@jacob-8
Copy link
Contributor Author

jacob-8 commented May 16, 2021

Still have the error, but found two more spots where it's thrown now. There is never a stack trace beyond the 1 line Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:' and its always a problem with a dynamic import of a file that has an absolute path beginning with C:\\dev\\... on my machine.

image

In debugging, line 67 of lib/bundle.js is throwing the error as we never get to setting the start variable:

image

That error and the import of the configFile are solved with using pathToFileURL(*).href and I get the message [svench] Compiled Svench runtime in 20.71s
image

Then it proceeds on and runs into the same errors in cli/commands/vite/dev.js detailed in my previous message containing the gist. I can solve the loading of Vite with pathToFileUrl, but still cannot fix loadSvenchifiedConfig() with this:
image
Changing the info.svench.dir path does however throw a different error:

C:\dev\kit-svench-2\node_modules\svench\lib\import-relative.cjs:1
Error: Cannot find module 'file:\\C:\\dev\\kit-svench-2\\node_modules\\svench\\presets\\vite'
Require stack:
- C:\dev\kit-svench-2\node_modules\svench\lib\import-relative.cjs

@rixo
Copy link
Owner

rixo commented May 17, 2021

OK thanks for all the debugging. I'll try your repro in a Windows box to fix all the problematic paths.

Note, however, that we don't really have support for Kit projects yet unfortunately...

rixo added a commit that referenced this issue May 27, 2021
@rixo
Copy link
Owner

rixo commented May 27, 2021

Hi @jwrunner! Sorry for taking so long to come back at this, things kinda crazy at works these days...

Anyway thanks again for your investigative work, it really helped. I was able to reproduce your issue in a Windows box, then I changed all dynamic imports that target an absolute path on the fs to a custom version that makes sure we're doing so with URLs. Now it seems to run well both on Windows and Linux, so we have a candidate fix.

Can you try svench@0.2.0-23 (currently tagged svench@next-win on npm) and see if it fixes the problem for you too?

@jacob-8
Copy link
Contributor Author

jacob-8 commented May 28, 2021

Wonderful! Running npx svench works on Windows with svench@0.2.0-23. Thank you for helping get this fixed as I've been chomping at the bit to try it out. Storybook is slow and large and your tool here is just perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants