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: importFile step fails with error "DOMParser is not defined" #210

Closed
squelchdesign opened this issue Mar 31, 2024 · 3 comments
Closed

Comments

@squelchdesign
Copy link

I am running wp-now with:

wp-now start --reset --blueprint=blueprint-wp-now.json

My blueprint-wp-now.json:

{
    "landingPage": "\/wp-admin\/themes.php?page=squelch-tabs-and-accordions-shortcodes",
    "preferredVersions": {
        "php": "8.1",
        "wp": "latest"
    },
    "phpExtensionBundles": [
        "kitchen-sink"
    ],
    "features": {
        "networking": true
    },
    "steps": [
        {
            "step": "defineWpConfigConsts",
            "consts": {
                "WP_DEBUG_LOG": true,
                "WP_ENVIRONMENT_TYPE": "development",
                "WP_DISABLE_FATAL_ERROR_HANDLER": true
            },
            "method": "define-before-run"
        },
        {
            "step": "installPlugin",
            "pluginZipFile": {
                "resource": "wordpress.org\/plugins",
                "slug": "font-awesome"
            },
            "options": {
                "activate": true
            }
        },
        {
            "step": "installPlugin",
            "pluginZipFile": {
                "resource": "wordpress.org\/plugins",
                "slug": "better-font-awesome"
            },
            "options": {
                "activate": true
            }
        },
        {
            "step": "installPlugin",
            "pluginZipFile": {
                "resource": "wordpress.org\/plugins",
                "slug": "block-for-font-awesome"
            },
            "options": {
                "activate": true
            }
        },
        {
            "step": "importFile",
            "file": {
                "resource": "url",
                "url": "https://github.com/squelchdesign/squelch-tabs-and-accordions-shortcodes/raw/oo-rewrite/sample-content.xml"
            }
        }
    ]
}

I get the following error:

Starting the server......
directory: /Users/lowey/devel/squelch-tabs-and-accordions-shortcodes
mode: plugin
php: 8.0
wp: latest
WordPress latest folder already exists. Skipping download.
SQLite folder already exists. Skipping download.
Created a fresh SQLite database and wp-content directory.
blueprint steps: 5
Blueprint step completed: defineWpConfigConsts
Blueprint step completed: installPlugin
Blueprint step completed: installPlugin
Blueprint step completed: installPlugin
ReferenceError: DOMParser is not defined
    at DOM (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:947:3)
    at Object.importFile (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:917:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async o (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:9285:30)
    at async Object.run (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:9212:23)
    at async runBlueprintSteps (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:9320:3)
    at async startWPNow (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/main.js:652:5)
    at async startServer (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/main.js:970:42)
    at async Object.handler (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/main.js:1152:25)
Error: Error when executing the blueprint step #4 ({"step":"importFile","file":{"resource":"url","url":"https://github.com/squelchdesign/squelch-tabs-and-accordions-shortcodes/raw/oo-rewrite/sample-content.xml"}}) : DOMParser is not defined
    at Object.run (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:9215:37)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async runBlueprintSteps (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:9320:3)
    ... 2 lines matching cause stack trace ...
    at async Object.handler (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/main.js:1152:25) {
  [cause]: ReferenceError: DOMParser is not defined
      at DOM (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:947:3)
      at Object.importFile (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:917:16)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async o (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:9285:30)
      at async Object.run (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:9212:23)
      at async runBlueprintSteps (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/node_modules/@wp-playground/blueprints/index.js:9320:3)
      at async startWPNow (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/main.js:652:5)
      at async startServer (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/main.js:970:42)
      at async Object.handler (file:///opt/homebrew/lib/node_modules/@wp-now/wp-now/main.js:1152:25)
}
Failed to start the server: Error when executing the blueprint step #4 ({"step":"importFile","file":{"resource":"url","url":"https://github.com/squelchdesign/squelch-tabs-and-accordions-shortcodes/raw/oo-rewrite/sample-content.xml"}}) : DOMParser is not defined

The WXR import file isn't anything fancy, it only contains a single post with some sample content so as to provide a consistent testing environment for plugin development.

#113 looked to have the same issue — although they were using a different step action — but it's been closed as fixed.

@squelchdesign
Copy link
Author

I've also just noticed that I specified PHP8.1 but wp-now is actually running 8.0…?

@squelchdesign
Copy link
Author

Ah, #379 in wordpress-playground offers an explanation.

Feel free to close this as a duplicate if it's not helpful/needed.

@bgrgicak
Copy link
Collaborator

bgrgicak commented Apr 1, 2024

Duplicate of WordPress/wordpress-playground#379

@bgrgicak bgrgicak closed this as completed Apr 1, 2024
@adamziel adamziel closed this as not planned Won't fix, can't repro, duplicate, stale Apr 2, 2024
johnhooks pushed a commit to johnhooks/playground-tools that referenced this issue Oct 11, 2024
* Introduce jsToPHPTranslator

It solves the problem of escaping arguments when writing PHP code in JavaScript.

Before:
```js
const code = `define('WP_HOME', "${absoluteUrl}");`
// if absoluteUrl contains the '"' character, this code will break
```

After:
```js
const code = t.define('WP_HOME', absoluteUrl).toString();
// absoluteUrl is correctly escaped and can even be an array
// or an object
```

* Format
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

No branches or pull requests

3 participants