Expand my Community achievements bar.

SOLVED

Not able to load dependent Npm Modules in Adobe IO Runtime

Avatar

Level 1

Hi All,

I have created the Node JS Post API module to be deployed to Adobe IO runtime.
I am making an Post call with query param and getting response when I directly run the index.js file my local.

 

Then I used wsk cli to create package and added the action inside it
https://developer.adobe.com/runtime/docs/guides/using/using_packages/
When I invoke the basic Hello name code by cmd -
wsk action invoke --result helloMyName/hello
I am getting the response

{"payload": "Hello stranger"}

Even I am able to deploy it using "wskdeploy" cmd and it is successful.
Then I modified the logic and added the Post Call login using "axios" module. I installed the axios package but still I am getting below axios module error while invoking the action.
C:/>wsk action invoke --result hellopackage/hello
{
"error": "An error has occurred: Error: Cannot find module 'axios'\nRequire stack:\n- /nodejsAction/runner.js\n- /nodejsAction/src/service.js\n- /nodejsAction/app.js"
}

I only have index.js file and no other file present in my local.

prajwal_akolnerkar8_1-1677599546073.png

At top of index.js file added - 
const axios = require('axios');
I have modified my manifest.yaml file as below with axios dependency but not able to deploy the package.

prajwal_akolnerkar8_0-1677599003523.png

Getting below error :
C:/>wskdeploy -m manifest.yaml
Error: manifest_parser.go [123]: [ERROR_YAML_PARSER_ERROR]: File: [manifest.yaml]:
==> yaml: unmarshal errors:
==> line 9: cannot unmarshal !!str `^1.3.4` into parsers.Dependency
The action invoke error state it is not able to find the axios module but I am not able to add it in the manifest.yaml file only. It's there in package.json and npm_module folder.
Could you please help me in understanding the best way to add dependent npm module in Adobe IO runtime.
Thanks,
Prajwal

Topics

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

1 Accepted Solution

Avatar

Correct answer by
Level 1

I normally add the dependency in the package.json file, for example:

 

"dependencies": {
"@adobe/aio-cli-plugin-cloudmanager": "^3.0.2",
"@adobe/aio-lib-state": "1.1.2",
"@adobe/aio-sdk": "^3.0.0",
"@adobe/exc-app": "0.2.47",
"@adobe/generator-add-action-generic": "^0.2.7",
"axios": "^0.27.2",
"core-js": "3.20.3",
"dataloader": "1.4.0",
"graphiql": "1.5.16",
"graphql": "14.7.0",
"graphql-tools": "3.1.1",
"js-yaml": "4.1.0",
"prop-types": "15.8.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"regenerator-runtime": "0.13.9",
"client-oauth2": "4.3.3",
"redis": "4.5.0",
"openwhisk": "^3.21.7"
},

View solution in original post

2 Replies

Avatar

Correct answer by
Level 1

I normally add the dependency in the package.json file, for example:

 

"dependencies": {
"@adobe/aio-cli-plugin-cloudmanager": "^3.0.2",
"@adobe/aio-lib-state": "1.1.2",
"@adobe/aio-sdk": "^3.0.0",
"@adobe/exc-app": "0.2.47",
"@adobe/generator-add-action-generic": "^0.2.7",
"axios": "^0.27.2",
"core-js": "3.20.3",
"dataloader": "1.4.0",
"graphiql": "1.5.16",
"graphql": "14.7.0",
"graphql-tools": "3.1.1",
"js-yaml": "4.1.0",
"prop-types": "15.8.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"regenerator-runtime": "0.13.9",
"client-oauth2": "4.3.3",
"redis": "4.5.0",
"openwhisk": "^3.21.7"
},

Hi @jafetsanchez,
I am missing one thing. When we add/remove/update dependencies we need to do "npm install". Thank you for your reponse. Now it is working.
I am focusing too much to manifest.yaml file and ignored package.json file.
Regards,
Prajwal