-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
PHP version: 8.3.19
Description
It seems like the server no longer starts properly, as NodeJS now tries to start the script as a module instead of CommonJS. Most likely introduced in a more recent version of NodeJS.
How to reproduce
<?php
require __DIR__ . '/vendor/autoload.php';
use GuzzleHttp\Server\Server;
Server::start();
echo "If you see this, then the bug has been resolved!";Possible Solution
The fix should be to turn the Javascript file into a CommonJS file, this should only require a file extension change from .js to .cjs.
Server.php should also be updated to call server.cjs instead of server.js.
Additional context
Output from /tmp/server.log:
/var/www/html $ cat /tmp/server.log
file:///var/www/html/vendor/guzzlehttp/test-server/src/server.js:41
var http = require('http');
^
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/var/www/html/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///var/www/html/vendor/guzzlehttp/test-server/src/server.js:41:12
at ModuleJob.run (node:internal/modules/esm/module_job:271:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:547:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5)
Node.js v22.13.1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels