Skip to content

Conversation

@brandonpayton
Copy link
Member

Motivation for the change, related issues

Running npx @wp-playground/cli server --debug currently fails for v3.0.38.

Unhandled rejection: ReferenceError: __dirname is not defined
    at withIntl (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@php-wasm/node/index.js:485:20)
    at async loadNodeRuntime (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@php-wasm/node/index.js:611:25)
    at async Object.createPhpRuntime (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@wp-playground/cli/worker-thread-v1.js:138:48)
    at async t (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@wp-playground/wordpress/index.js:451:15)
    at async PHPProcessManager.phpFactory (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@php-wasm/universal/index.js:2559:21)
    at async PHPProcessManager.doSpawn (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@php-wasm/universal/index.js:2363:17)
    at async PHPProcessManager.getPrimaryPhp (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@php-wasm/universal/index.js:2289:135)
    at async PHPRequestHandler.getPrimaryPhp (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@php-wasm/universal/index.js:2585:12)
    at async L (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@wp-playground/wordpress/index.js:384:13)
    at async V (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@wp-playground/wordpress/index.js:380:10)

I think our tests for built npm packages should have caught this before merging, so I would like to look into that before merging this fix.

cc @mho22

Implementation details

Use conditional logic to determine the module directory: prefer __dirname when available (CommonJS), fall back to import.meta.dirname (ESM). Also switch to path.join for more robust path construction.

Testing Instructions (or ideally a Blueprint)

  • CI

Use conditional logic to determine the module directory: prefer __dirname
when available (CommonJS), fall back to import.meta.dirname (ESM). Also
switch to path.join for more robust path construction.
@brandonpayton brandonpayton requested a review from a team January 6, 2026 22:38
@brandonpayton brandonpayton self-assigned this Jan 6, 2026
const dataPath = `${__dirname}/shared/${dataName}`;
const moduleDir =
typeof __dirname !== 'undefined' ? __dirname : import.meta.dirname;
const dataPath = path.join(moduleDir, 'shared', dataName);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to fix the missing __dirname bug, this PR switches from string concat to explicit path concat.

@brandonpayton
Copy link
Member Author

I think our tests for built npm packages should have caught this before merging, so I would like to look into that before merging this fix.

Confirmed. This issue was introduced by 74446e7. The tests on that commit encountered the error but somehow did not fail the CI job:
https://github.com/WordPress/wordpress-playground/actions/runs/20741861135/job/59550114727#step:4:1869

Looking into it.

@brandonpayton
Copy link
Member Author

Our ES module tests for built NPM packages did not consider timeouts to be failures. That should be fixed now.

@brandonpayton
Copy link
Member Author

Nice! The built package tests are failing due to the missing __dirname bug here:
https://github.com/WordPress/wordpress-playground/actions/runs/20764816212/job/59628496577#step:4:2608

Now that the __dirname fix is restored, we can merge this once the latest CI tests pass.

I have to go AFK shortly and will wait until I am back in 3-4 hours to merge and publish new NPM packages. That way, there is opportunity to confirm all is well with the latest version before moving on to other things.

To others on the team, please feel free to merge and publish before then. The latest published version of Playground CLI is currently broken.

@brandonpayton brandonpayton merged commit a7cad67 into trunk Jan 7, 2026
33 checks passed
@brandonpayton brandonpayton deleted the pg-fix-missing-dirname branch January 7, 2026 02:51
@mho22
Copy link
Collaborator

mho22 commented Jan 7, 2026

@brandonpayton Thank you!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants