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

wp-now: ReferenceError: DOMParser is not defined while installing the plugin #113

Closed
jakubmikita opened this issue Oct 3, 2023 · 6 comments
Assignees

Comments

@jakubmikita
Copy link

jakubmikita commented Oct 3, 2023

My blueprint:

{
    "$schema": "https://playground.wordpress.net/blueprint-schema.json",
    "landingPage": "/wp-admin/",
    "preferredVersions": {
        "php": "8.0",
        "wp": "latest"
    },
    "steps": [
        {
            "step": "login",
            "username": "admin",
            "password": "password"
        },
        {
            "step": "installPlugin",
            "pluginZipFile": {
                "resource": "wordpress.org/plugins",
                "slug": "notification"
            },
            "options": {
                "activate": true
            }
        }
    ]
}

And the result:

kuba@Kuba:/mnt/c/Users/Kuba/www/now$ wp-now start --blueprint=env.json
Starting the server......
directory: /mnt/c/Users/Kuba/www/now
mode: playground
php: 8.0
wp: latest
WordPress latest folder already exists. Skipping download.
SQLite folder already exists. Skipping download.
blueprint steps: 2
Blueprint step completed: login
Proceeding without the Notification theme. Could not install it in wp-admin. The original error was: ReferenceError: DOMParser is not defined
ReferenceError: DOMParser is not defined
    at S (file:///home/kuba/.nvm/versions/node/v20.8.0/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:35:3)
    at Module.xe [as installPlugin] (file:///home/kuba/.nvm/versions/node/v20.8.0/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:351:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async o (file:///home/kuba/.nvm/versions/node/v20.8.0/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:2044:30)
    at async Object.run (file:///home/kuba/.nvm/versions/node/v20.8.0/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:2007:21)
    at async yt (file:///home/kuba/.nvm/versions/node/v20.8.0/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:2079:3)
    at async startWPNow (file:///home/kuba/.nvm/versions/node/v20.8.0/lib/node_modules/@wp-now/wp-now/main.js:596:5)
    at async startServer (file:///home/kuba/.nvm/versions/node/v20.8.0/lib/node_modules/@wp-now/wp-now/main.js:865:42)
    at async Object.handler (file:///home/kuba/.nvm/versions/node/v20.8.0/lib/node_modules/@wp-now/wp-now/main.js:1037:25)
Blueprint step completed: installPlugin
Server running at http://localhost:8881
spawn xdg-open ENOENT

The plugin can be installed just fine from the wp-admin.

Also looks like there's a small typo:

Proceeding without the Notification theme

@adamziel adamziel added Bug Something isn't working and removed Bug Something isn't working labels Oct 3, 2023
@adamziel
Copy link
Collaborator

adamziel commented Oct 3, 2023

@sejas This is because the activatePlugin step used to rely on the DOMParser API. It no longer does thanks to this excellent PR by @eliot-akira: WordPress/wordpress-playground#427. Was that already published to npm in the 0.2.0 release? If so, then numping the @wp-playground/blueprints dependency to 0.2.0 will solve this.

@sejas
Copy link
Collaborator

sejas commented Oct 4, 2023

I've created a draft PR, but it's not so easy. We may need to modify the blueprints to be more isomorphic.

@adamziel, would you have bandwidth this week to help me a bit?

@adamziel
Copy link
Collaborator

adamziel commented Oct 6, 2023

@sejas I replied in that PR, thank you for looking into this!

@sejas
Copy link
Collaborator

sejas commented Feb 5, 2024

After updating the dependencies that add the Polyfills, I'm still seeing an error thrown by crypto.randomUUID. I created a PR that fixes it. #153

adamziel pushed a commit to WordPress/wordpress-playground that referenced this issue Feb 5, 2024
…1000)

- Similar to #875
- Related to WordPress/playground-tools#113

## What is this PR doing?
It imports the native library `crypto` and makes it globally available
in the runtime.

## What problem is it solving?

When using blueprints that install plugins or themes, it generates a
random folder using
[`crypto`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto)`.
That library is available in the browsers by default, but for node we
need to import it.

Note that it do not install any dependency since Crypto is already built
in NodeJS, but it's not imported by default.
I decided to use [`node:crypto`](https://nodejs.org/api/webcrypto.html)
which has `webcrypto` and will be a better match. It's available sine
Node v15.

The other alternative is normal
[crypto](https://nodejs.org/api/crypto.html)
https://nodejs.org/docs/latest-v14.x/api/crypto.html, which also has
`crypto.randomUUID`. It's available since Node v14.

## How is the problem addressed?

It adds a new Polyfill for crypto.

## Testing Instructions

1. Comment the first line `import './crypto';` on
`packages/php-wasm/node-polyfills/src/lib/crypto.spec.ts`
2. Run `npx nx test php-wasm-node-polyfills`
3. Observe the tests fail
4. Uncomment first line `import './crypto';` on
`packages/php-wasm/node-polyfills/src/lib/crypto.spec.ts`
5. Run `npx nx test php-wasm-node-polyfills`
6. Observe the tests pass
@adamziel
Copy link
Collaborator

adamziel commented Mar 4, 2024

@sejas can this issue be closed now?

@sejas
Copy link
Collaborator

sejas commented Mar 6, 2024

Yes!, Let's close it, the installPlugin and installTheme blueprints are already fixed. 👌

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

Successfully merging a pull request may close this issue.

3 participants