Learn icon indicating copy to clipboard operation
Learn copied to clipboard

Use cross-env to set environment variables

Open jonathanbossenger opened this issue 6 months ago • 4 comments

Closes #3188

Needs testing

  • [ ] macOS
  • [ ] Windows
  • [ ] Linux (Ubuntu)

Testing instructions:

  1. Clone this repository (if you haven't already): git clone https://github.com/WordPress/Learn.git
  2. Check out the cross-env branch: git checkout cross-env
  3. Follow the setup instructions in the readme. The local environment should be successfully set up

jonathanbossenger avatar Jun 14 '25 16:06 jonathanbossenger

Hello, On Windows, I still have this issue.

PS C:\www\learn-wp> yarn run create yarn run v1.22.22 $ composer install && yarn setup:tools && yarn build && yarn run install:env Installing dependencies from lock file (including require-dev) Verifying lock file contents can be installed on current platform. Nothing to install, update or remove Generating autoload files 5 packages you are using are looking for funding. Use the composer fund command to find out more! $ cross-env TEXTDOMAIN=wporg-learn composer exec update-configs <3>WSL (397 - Relay) ERROR: CreateProcessCommon:725: execvpe(/bin/bash) failed: No such file or directory Script update-configs handling the __exec_command event returned with error code 1 error Command failed with exit code 1.

Docker is running, but no particular image has been installed so far.

timboomerang avatar Jun 16 '25 08:06 timboomerang

@timboomerang thanks for the feedback, I still need to test it on Windows myself.

jonathanbossenger avatar Jul 02 '25 11:07 jonathanbossenger

@jonathanbossenger @timboomerang

I've tested the setup on all three operating system environments, and I can confirm that it is working.

But, in order to run it on Windows, we must make some minor modifications and install additional apps (if they are not preinstalled).

Steps for installing on Windows:

  • Using chocolately, install zip and unzip (if they don't already exist on the system) chocolately install zip chocolately install uzip
  • also, install cross-env npm package if not installed using npm install -g cross-env
  • important note: to be able to run all shell scripts during the install phase, you must use the git-bash, not other terminals like WSL, PowerShell, CMD. The file path is different in Windows and Unix-like systems (slash and backslash difference).
  • update line 27 in file package.json to this - "install:env": "bash ./bin/index.sh",.
    If you don't add bash as the command interpreter, the index.sh script will not be executed, and we will get a blank WordPress instance.
  • line 33 stays as @jonathanbossenger suggested - "setup:tools": "cross-env TEXTDOMAIN=wporg-learn composer exec update-configs",

Once you've made these modifications, follow the setup instructions to ensure everything starts correctly.

rjekic avatar Jul 12 '25 19:07 rjekic

Thank you for helping to test @rjekic. I just haven't had time. I'm going to be AFK next week, but I'll take a look as soon as I get back.

jonathanbossenger avatar Jul 13 '25 16:07 jonathanbossenger