-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
path/filepath: WebAssembly uses *nix conventions on Windows #43768
Comments
I don't know how applicable it is here, but in Yarn we also happen to deal with filesystem path portability, and our solution to this problem is to always only work with Posix paths (ie even on Windows our path representation is |
Since the title now implies the problem is just with |
I think is more a WASI issue |
When run sample code above on linux it prints false too! It's not just about WebAssembly. Python solved this problem with different module for unix and windows. That is posixpath and ntpath according to docs https://docs.python.org/3/library/os.path.html |
It looks like this also affects other modules outside of |
This comment was marked as resolved.
This comment was marked as resolved.
Currently wasm target uses the Considering that wasm may run on different platforms, maybe calling the absolute path check in the js environment would be a good idea? Otherwise we would have to create a huge function that can determine the path format of all supported platforms. We have https://nodejs.org/api/path.html#pathisabsolutepath in Node.js. For browser environments, perhaps allowing users to create flexible polyfills would be a more compatible idea. |
Change https://go.dev/cl/604695 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Here's a quick demonstration of the problem. Make a file called
main.go
that looks like this:Run this program natively on Windows:
Run this program via WebAssembly on Windows:
What did you expect to see?
I expected to see
IsAbs: true
in both cases.What did you see instead?
I see
IsAbs: true
when running a native executable on Windows but I seeIsAbs: false
when running via WebAssembly on Windows.I'm the developer behind esbuild, a JavaScript bundler written in Go. I publish native executables for all major operating system and architecture combinations, and I also separately publish a WebAssembly executable. The WebAssembly executable is intended to enable people to use esbuild in the browser and also in scenarios where they want to use esbuild outside of the browser in an os-independent context, which is the promise of WebAssembly.
Here is the context for this issue: evanw/esbuild#687. The Yarn JavaScript package manager would like to use the WebAssembly version of esbuild instead of the native version. They try to avoid install scripts with platform-specific behavior since it messes with their preferred package installation strategy. Thus the same directory tree must be able to work on all platforms.
I have (perhaps incorrectly) assumed that Go's WebAssembly build target produces a cross-platform executable. This doesn't appear to be the case. It also doesn't appear to be something that can be fixed in a backwards-compatible manner, so I can understand if you either won't or can't fix it. It does seem like a bug to me because it violated my expectations of what the behavior should be, so I have reported it as a bug. But it's also possible that the WebAssembly build target only works in Unix-style environments by design and I was incorrect in assuming it would be cross-platform.
Regardless, I could use some advice for what to do here. Am I on my own for how to fix this? I imagine I could essentially fork the Go standard library and try to include both copies in the WebAssembly build. But I would prefer not to do that if possible.
The text was updated successfully, but these errors were encountered: