Expand my Community achievements bar.

How to use external module inside own actions on Adobe runtime

Avatar

Level 2

Hello,

 

I'm new in Adobe Runtime and trying to learn usage of the actions. But i'm stuck with usage of a new modules.

For example i have following action created:

const fetch = require('node-fetch')
const FormData = require('form-data')
async function main(params) {
        let formDataVar = new FormData();
}
Where before that i have install my module : npm install --save form-data
It's visible inside my package.json:
{
  "name": "runtimeHelloWorld",
  "version": "0.0.1",
  "private": true,
  "dependencies": {
    "@adobe/aio-sdk": "^3.0.0",
     ...
    "core-js": "^3.6.4",
    "form-data": "^4.0.0",
    "node-fetch": "^2.6.0",
    ...
  },

I have executed "npm install" and build my app as well. But when i create or update my action after invoke it i got:
{
"error": "Initialization has failed due to: Error: Cannot find module 'form-data'
Require stack:
- /nodejsAction/runner.js
- /nodejsAction/src/service.js
- /nodejsAction/app.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at eval (eval at NodeActionRunner.init (/nodejsAction/runner.js:92:45), <anonymous>:2:18)
at eval (eval at NodeActionRunner.init (/nodejsAction/runner.js:92:45), <anonymous>:34:14)
at NodeActionRunner.init (/nodejsAction/runner.js:92:45)
at doInit (/nodejsAction/src/service.js:229:31)
at initCode (/nodejsAction/src/service.js:168:24)
at /nodejsAction/app.js:74:13"
}

What is that i'm doing wrong or missing into my actions?
P.S. if i remove declaration of the form-data my action is working fine locally. 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

2 Replies

Avatar

Level 2

Hello,

 

I'm replying to myself in order to help others since there is not much of documentation into matter of Runtime.

Issue with external modules is that they are all installed and added only locally. Example if you execute

"npm install form-data --save" it will only download the library on your local environment. But the action you are writing is uploaded to the Server.

For this reason after many try and errors here is what has worked for me, execute this on the command com:

aio app buld

aio app deploy

aio app run

The last step will give URL where the server will execute actions. When you execute the action on the server side, you can check the result using :

wsk activation list  -- This will give all of the actions executed

Get the activation Id and check the result example:

wsk activation get e93b4aXXXXXXcb51b87ff

 

I'm not sure that my explanation is correct, but that is working for me. If anyone else has something to add it could will be useful for others. As mentioned already it's not many information about this product. 

Avatar

Level 1

Hi @yumera 
What you said is correct, when ever you are adding new modules to our actions we need to run the build, deploy, run, and then activate your action as mentioned.