Node dependencies are not installed / loaded from parent project
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");
AFAIR this breaks the Node.js PHP.wasm builds.
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.
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
This turned out to be a build issue and it was solved in https://github.com/WordPress/wordpress-playground/pull/1585