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

Compatibility with Windows and WSL #435

Open
t-hamano opened this issue May 24, 2023 · 18 comments
Open

Compatibility with Windows and WSL #435

t-hamano opened this issue May 24, 2023 · 18 comments

Comments

@t-hamano
Copy link
Contributor

I want to contribute to this project and attempted to build the project. I am using Windows OS and could not build it because of the UNIX-derived commands used.

For example, the cp command is not recognized as follows (the equivalent command is copy on Windows) :

nx run wp-now:"build:bundle"

> nx run wp-now:"build:bundle"

'cp' is not recognized as an internal or external command,
operable program or batch file.
Warning: run-commands command "cp packages/wp-now/public/* dist/packages/wp-now" exited with non-zero status code

 ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 >  NX   Ran target build:bundle for project wp-now (653ms)
 
    ×    1/1 failed
    √    0/1 succeeded [0 read from cache]

So, after a quick look at the commands property of project.json, it seems that the following commands are not available on Windows:

  • rm
  • zip
  • cp
  • cat

The three solutions I know of are as follows:

I know it is very difficult to build an OS-independent development environment for such an advanced project, but I would be happy to help in any way I can.

@dmsnell
Copy link
Member

dmsnell commented May 24, 2023

@t-hamano have you tried using the Windows Subsystem for Linux?
It was Microsoft's response to these kind of recurring issues and it's gotten quite good.

https://learn.microsoft.com/en-us/windows/wsl/about

@t-hamano
Copy link
Contributor Author

@dmsnell
Thanks for the reply.

have you tried using the Windows Subsystem for Linux?

Yes, I am developing on WSL2 primarily for the Gutenberg Project.

However, I could not build the project even on WSL. The following error occurs (However, this might be a problem in my environment):

$ nx preview wp-now start
/mnt/c/Users/tetsuaki.hamano/AppData/Local/Volta/bin/nx: line 1: cmd: command not found

I also believe that debugging on Windows OS is necessary to resolve Windows-specific issues such as those reported in WordPress/playground-tools#11.

@dmsnell
Copy link
Member

dmsnell commented May 24, 2023

@t-hamano was just discussing this in another issue. nx is a runtime dependency not specified, so it looks like the project is working in WSL for you, but depending on nx at the runtime is itself a problem.

workaround for now to confirm the problem is npm install -g nx and try again

@adamziel
Copy link
Collaborator

adamziel commented May 24, 2023

It would be great not to rely on the global nx command.

About rm, cp, and others – I'm conflicted. On one hand, it's really convenient to use them and node packages like rimraf are portable but also tend to be slower, behave differently, and require consulting the documentation frequently. What do you think @dmsnell ?

@t-hamano
Copy link
Contributor Author

@dmsnell
Thank you, after installing nx globally, I was able to run npm run dev and confirm that Playground was launched in the browser!

The nx preview wp-now start command also executed successfully, but when I accessed http://127.0.0.1:8881/, I got an ERR_CONNECTION_REFUSED error. If this does not seem to be a problem in my environment, I will report it separately.

@adamziel
Copy link
Collaborator

adamziel commented May 24, 2023

CCing @danielbachhuber about the connection error.

@t-hamano WSL should just allow you to use any ports, right? I just wanted to confirm you don't have to explicitly allow network traffic.

@t-hamano
Copy link
Contributor Author

@adamziel

According to this comment from the WSL project, my understanding is as follows:

  • Currently wp-now is listening on 127.0.0.1 (ipv4 address)
  • Windows host OS resolves localhost to ::1 (ipv6 address)
  • Therefore, the address that wp-now is listening to cannot be reached

However, localhost:5400 that npm run dev is listening to is correctly accessible. I can also access localhost:8888​ when wp-env is started with WSL.

Therefore, one solution might be to change the address that wp-now listens on to localhost.

@danielbachhuber
Copy link
Member

Therefore, one solution might be to change the address that wp-now listens on to localhost.

@t-hamano Want to submit a PR with your suggested changes?

@t-hamano
Copy link
Contributor Author

@t-hamano Want to submit a PR with your suggested changes?

Yes, I still lack understanding about this project, but I will try to submit a PR soon.

@eliot-akira
Copy link
Collaborator

I'm not sure if it's related, but there was an issue with using localhost for absolute URL when loading PHP WASM on the server side (Node.js). The temporary solution was to use 127.0.0.1.

Just wanted to mention it, in case you see the same error.

@adamziel
Copy link
Collaborator

adamziel commented May 25, 2023

@t-hamano I believe it's hardcoded in this line:

const url = `http://127.0.0.1:${port}/`;

@eliot-akira good point! Perhaps it would work now that localhost resolves to 127.0.0.1: 4c40c55

adamziel pushed a commit that referenced this issue May 30, 2023
See [this
comment](#435 (comment)).

## What?

This PR changes the URL that `wp-now` listens on from `127.0.0.1` to
localhost.

## Why?

When I run `wp-now start` in WSL (a Windows virtual environment), it
listens on `127.0.0.1` (ipv4 address).
However, when I access the URL on the host OS, it resolves `to::1` (ipv6
address), so I believe this is why the server is unreachable.

## Testing Instructions

- run `nx preview wp-now start`
- Confirm that the console displays the expected logs: `Server running
at http://localhost:8881/`
- Confirm that the WordPress site is displayed when accessing
`http://localhost:8881/`.
- Conform that WordPress Address and Site Address settings are
`http://localhost:8881/`.
- Confirm that all resources such as CSS and JS are also loaded at this
URL and that no errors are output to the console.
@danielbachhuber
Copy link
Member

Another contributor hitting the original report WordPress/playground-tools#66

Pookie717 added a commit to Pookie717/wordpress-playground that referenced this issue Oct 1, 2023
See [this
comment](WordPress/wordpress-playground#435 (comment)).

## What?

This PR changes the URL that `wp-now` listens on from `127.0.0.1` to
localhost.

## Why?

When I run `wp-now start` in WSL (a Windows virtual environment), it
listens on `127.0.0.1` (ipv4 address).
However, when I access the URL on the host OS, it resolves `to::1` (ipv6
address), so I believe this is why the server is unreachable.

## Testing Instructions

- run `nx preview wp-now start`
- Confirm that the console displays the expected logs: `Server running
at http://localhost:8881/`
- Confirm that the WordPress site is displayed when accessing
`http://localhost:8881/`.
- Conform that WordPress Address and Site Address settings are
`http://localhost:8881/`.
- Confirm that all resources such as CSS and JS are also loaded at this
URL and that no errors are output to the console.
@ajitbohra
Copy link
Member

@adamziel
Copy link
Collaborator

@ajitbohra The URL issue should now be solved, but the larger question about Windows compatibility still stands. Perhaps requiring WSL as a dependency would be a good middle-ground. @t-hamano – is everything working for you on WSL now?

@t-hamano
Copy link
Contributor Author

I've been away from this project for a while, so could you please tell me what I should check?

For the time being, when I executed npm run preview on WSL, the server started up, but the page was not displayed on either http://localhost:5932/ or http://127.0.0.1:5932/.

6af728706e50045e825cc64bf9668339.mp4

@adamziel
Copy link
Collaborator

Thank you for testing @t-hamano! That's useful for the core Wordpress Playground repo.

I was about to ask if you could also try wp-now from https://github.com/WordPress/playground-tools/, but I just saw the absoluteUrl option @ajitbohra linked to is not actually exposed to the CLI:

CleanShot 2023-10-16 at 17 46 22@2x

So yes, this issue still stands.

@adamziel adamziel changed the title Consider not using OS-dependent commands Compatibility with Windows and WSL Oct 16, 2023
@t-hamano
Copy link
Contributor Author

t-hamano commented Oct 17, 2023

Regarding wp-now, it seems to be working mostly fine, both in the case of developing the playground-tools project itself and using the library. The command that is failing may be a problem with my environment or testing procedure 🤔

playground-tools project development

After cloning the playground-tools repo and running npm install, I ran the following command:

  • npm run build: ✅ The build completes successfully
  • nx preview wp-now start: ✅ Server starts and WP site works
  • npm run dev: ⚠️ got the following error > NX Cannot find project 'playground-website'
  • npm run preview: ⚠️ got the following error > NX Cannot find project 'playground-website'

wp-now package

  • npm install -g @wp-now/wp-now
  • wp-now start: ✅ Server starts and WP site works

Is there anything else I should check?

@adamziel
Copy link
Collaborator

This is golden, thank you so much @t-hamano!

CCing @sejas on the playground-tools errors, which are likely a matter of removing playground-website from some config as it's not a project living in that repo.

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

No branches or pull requests

6 participants