When I create a Node.js v16 function action from a zip file containing a simple estest.js
:
function main(params) {
return { message: 'Hello World' };
}
and package.json
containing "type": "module"
I get:
{
"error": "Initialization has failed due to: Error [ERR_REQUIRE_ESM]: require() of ES Module /nodejsAction/1AfjbP59/estest.js from /nodejsAction/runner.js not supported.estest.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains \"type\": \"module\" which declares all .js files in that package scope as ES modules.\nInstead rename estest.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change \"type\": \"module\" to \"type\": \"commonjs\" in /nodejsAction/1AfjbP59/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).\n\n at eval (eval at <anonymous> (/nodejsAction/runner.js:51:31), <anonymous>:1:1)\n at /nodejsAction/runner.js:51:31"
}
I have not found any IBM Cloud documentation which states that only the legacy Common JS style is supported.
EDIT:
Action created using:
ibmcloud fn action create test/estest estest.zip --kind nodejs:16