1

I'm trying to upload a zipped action to IBM's OpenWhisk.

"Initialization has failed due to: Action entrypoint 'main' is not a function."

But I'm quite sure that "main" is a function, and I've tried defining it in multiple ways. As tutorials suggest, I've tried both:

function processComment(params) {
    // some code
    return {success:1};
}
exports.main = processComment;

and

function main(params) {
    // some code
    return {success:1};
}

This code is all contained in a file is called index.js, and I've tried it with and without the following line in my package.json:

"main": "index.js",

I even looked up the relevant code in OpenWhisk, and it seems to be a straightforward type check to see if main is a function:

if (typeof thisRunner.userScriptMain !== 'function') {
    throw "Action entrypoint '" + message.main + "' is not a function.";
}

So I assume it's just not finding "main" in the right place... But I'm really lost. Can somebody help me out?

JJJ
  • 32,902
  • 20
  • 89
  • 102
Daniel
  • 2,956
  • 2
  • 15
  • 12

1 Answers1

2

Are you using a zip file? If not you’ve hit a limitation of the current node.js runtime as explained in this issue https://github.com/apache/incubator-openwhisk-runtime-nodejs/issues/14 which requires a zipped source file instead.

If you are using a zip, did you place the package.json and index.js filed at the root path?

As a zip file:

index.js:

function processComment(params) {
    // some code
    return {success:1};
}
exports.main = processComment;

package.json:

{
  "name": "my-action",
  "main": "index.js"
}

And using the CLI:

$ zip s.zip index.js package.json
$ wsk action create s s.zip --kind nodejs:6
$ wsk action invoke s -r
{
    "success": 1
}
user6062970
  • 831
  • 4
  • 5
  • I didn't use the "zip" command, because I'm in windows -- I used 7zip's explorer context menu option, but I can confirm that index.js and package.json are both at the root. So... yeah, this is a mystery? – Daniel Jan 29 '18 at 00:45
  • One note: I made the action in the IBM web interface, and then updated it with a zip file once I realized that I needed that to do that to get a package.json into the mix. – Daniel Jan 29 '18 at 00:58
  • You updated the action with the zip file using the web interface or the cli? – user6062970 Jan 29 '18 at 04:08
  • Can you upload your sample zip file somewhere? I'm happy to test it out and check the commands are working. – James Thomas Jan 29 '18 at 09:45