wordpress-playground icon indicating copy to clipboard operation
wordpress-playground copied to clipboard

Node dependencies are not installed / loaded from parent project

Open fabiangigler opened this issue 1 year ago • 3 comments

I'm trying to use php-wasm inside a Next.js API Route and am facing a dependency resolving error.

These inline require functions in dist/packages/php-wasm/node/index.cjs are the ones making troubles:

const isValidUTF8 = require("utf-8-validate");
const bufferUtil = require("bufferutil");

fabiangigler avatar Jun 13 '24 17:06 fabiangigler

AFAIR this breaks the Node.js PHP.wasm builds.

adamziel avatar Jul 03 '24 15:07 adamziel

On a second look this code snippet is a bundled part of the ws Node package that is a dependency of @php-wasm/node.

    } else if (!process.env.WS_NO_UTF_8_VALIDATE) {
      try {
        const isValidUTF8 = require("utf-8-validate");
        module2.exports.isValidUTF8 = function(buf) {
          return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
        };
      } catch (e) {
      }
    }

I think the problem was the way we were importing the file directly from the build directory without installing its dependencies. Let's confirm once the new @php-wasm/node is published.

adamziel avatar Jul 03 '24 21:07 adamziel

ws dependency is at risk for now :

npm audit
# npm audit report

ws  8.0.0 - 8.17.0
Severity: high
ws affected by a DoS when handling a request with many HTTP headers - https://github.com/advisories/GHSA-3h5v-q93c-6h6q
fix available via `npm audit fix --force`
Will install @php-wasm/[email protected], which is a breaking change
node_modules/ws
  @php-wasm/node  >=0.1.18
  Depends on vulnerable versions of ws
  node_modules/@php-wasm/node

2 high severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

@php-wasm/node should probably update the version of ws

mho22 avatar Jul 04 '24 11:07 mho22

This turned out to be a build issue and it was solved in https://github.com/WordPress/wordpress-playground/pull/1585

adamziel avatar Jul 31 '24 11:07 adamziel