scaleway/serverless-functions-node

Cannot find module 'node:http'

smichea opened this issue ยท 2 comments

Community Note

  • Please vote on this issue by adding a ๐Ÿ‘ reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

What did you do?

try to execute a basic handler handler.js

import { pathToFileURL } from "url";

export { handle };

function handle(event, context, cb) {
    if (event.httpMethod !== "POST") {
        return {
            statusCode: 405,
            body: "Method Not Allowed",
            headers: {
                "Content-Type": "text/plain",
            },
        };
    }
   return {
        body: process.version,
        statusCode: 200,
    };
};

// This will execute when testing locally, but not when the function is launched
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
    import("@scaleway/serverless-functions").then(scw_fnc_node => {
        scw_fnc_node.serveHandler(handle, 8080);
    });
}

with this package.json

{
    "name": "fct-game-record",
    "version": "1.0.0",
    "main": "handler.js",
    "type": "module",
    "keywords": [],
    "author": "sebastien michea",
    "license": "ISC",
    "devDependencies": {
        "serverless-scaleway-functions": "^0.4.6"
    }
}

What did you expect to see?

server starting and exposing my handler endpoint

What did you see instead?

(base) ubuntu@LAPTOP-CVF:~/development/skilz/fct-game$ node handler.js
(node:66172) UnhandledPromiseRejectionWarning: Error: Cannot find module 'node:http'
Require stack:
- /home/ubuntu/node_modules/fastify/fastify.js
- /home/ubuntu/node_modules/@scaleway/serverless-functions/framework/dist/local/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/ubuntu/node_modules/fastify/fastify.js:6:14)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
(node:66172) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:66172) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

What version of Node are you using (node --version)?

$ node --version

v12.22.9

Does this issue reproduce with the latest release?

yes

Hello,

The version of Node you are currently using (Node 12) is not supported by SCALEWAY Serverless functions, and there are no plans to support it. Currently, the supported Node versions are Node 14, Node 16, Node 18, and Node 20 (in beta).

Could you please try upgrading to one of these supported versions and see if the issue persists?

Closing because of inactivity. @smichea feel free to reopen if @Bemilie's suggestion doesn't help.