Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node.js default example fails due to dependency errors despite running in a default Docker image #192

Open
anna-geller opened this issue Dec 4, 2024 · 4 comments
Assignees
Labels
area/backend Needs backend code changes area/plugin Plugin-related issue or feature request bug Something isn't working

Comments

@anna-geller
Copy link
Member

anna-geller commented Dec 4, 2024

Describe the issue

id: outputs_nodejs
namespace: company.team

description: This flow will install the npm package in a Docker container, and use kestra's NodeJS Commands task to run the script.

tasks:
  - id: run_nodejs_commands
    type: io.kestra.plugin.scripts.node.Commands
    inputFiles:
      output_nodejs.js: |
        const requestify = require('requestify');
        const Kestra = require('@kestra-io/libs');

        function GetDockerImageDownloads(imageName){
          // Queries the Docker Hub API to get the number of downloads for a specific Docker image.
          var url = `https://hub.docker.com/v2/repositories/${imageName}/`
          console.log(url)
          requestify.get(url)
            .then(function(response) {
              result = JSON.parse(response.body);
              Kestra.outputs({"pull_count": result['pull_count']})
              return result['pull_count'];
            })
            .catch(function(error) {
              console.log(error);
            })
        }

        GetDockerImageDownloads("kestra/kestra")      
    taskRunner:
      type: io.kestra.plugin.scripts.runner.docker.Docker
    containerImage: node:slim
    warningOnStdErr: false
    beforeCommands:
      - npm install requestify
      - npm install @kestra-io/libs
    commands:
      - node outputs_nodejs.js

  - id: log_downloads
    type: io.kestra.plugin.core.log.Log
    message: "Number of downloads: {{ outputs.run_nodejs_commands.vars.pull_count }}"

From https://kestra.io/docs/how-to-guides/javascript#variable-output

Environment

  • Kestra Version: develop
@anna-geller anna-geller added bug Something isn't working area/plugin Plugin-related issue or feature request labels Dec 4, 2024
@kestrabot kestrabot bot added this to Issues Dec 4, 2024
@github-project-automation github-project-automation bot moved this to Backlog in Issues Dec 4, 2024
@anna-geller anna-geller added the area/backend Needs backend code changes label Dec 4, 2024
@wrussell1999
Copy link
Member

wrussell1999 commented Dec 4, 2024

More context, I was only able to reproduce this error when using @kestra-io/libs, e.g. it was installed in beforeCommands like the example above and used in the code.

Error message:

2024-12-04 14:23:11.624 file:///tmp/kestra-wd/tmp/4Qwb7lKwsPOjx8nSp1WVh8/node_modules/@kestra-io/libs/src/index.js:86
2024-12-04 14:23:11.625 module.exports = Kestra;
2024-12-04 14:23:11.625 ^
2024-12-04 14:23:11.625
2024-12-04 14:23:11.625 at ModuleJobSync.runSync (node:internal/modules/esm/module_job:395:35)
2024-12-04 14:23:11.625 at Module._compile (node:internal/modules/cjs/loader:1528:5)
2024-12-04 14:23:11.625 ReferenceError: module is not defined
2024-12-04 14:23:11.625 at loadESMFromCJS (node:internal/modules/cjs/loader:1376:24)
2024-12-04 14:23:11.625 at file:///tmp/kestra-wd/tmp/4Qwb7lKwsPOjx8nSp1WVh8/node_modules/@kestra-io/libs/src/index.js:86:1
2024-12-04 14:23:11.625 at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:329:47)
2024-12-04 14:23:11.625 at Module.load (node:internal/modules/cjs/loader:1303:32)
2024-12-04 14:23:11.625 at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
2024-12-04 14:23:11.625 at Function._load (node:internal/modules/cjs/loader:1117:12)
2024-12-04 14:23:11.625
2024-12-04 14:23:11.625 at TracingChannel.traceSync (node:diagnostics_channel:322:14)
2024-12-04 14:23:11.625 Node.js v23.3.0
2024-12-04 14:23:11.625 at Object..js (node:internal/modules/cjs/loader:1698:10)
2024-12-04 14:23:12.087 Command failed with exit code 1

Which follows back to this line: https://github.com/kestra-io/libs/blob/e06e529b425fad6c2e414ab4972fa6f3d7714861/javascript/src/index.js#L86 and this commit: kestra-io/libs@c7e0e74#diff-78d7fb98aeedb949389f105a6a0ffab1a69e3df69cb1cc21035f2bbeaf86e879

@wrussell1999
Copy link
Member

Related: kestra-io/libs#9

@anna-geller
Copy link
Member Author

we should check with the latest version of node.js

@wrussell1999
Copy link
Member

wrussell1999 commented Dec 16, 2024

I tried this with 22.12.0 and 23.4.0 and both have the same error. Looking online, it seems that the ReferenceError: module is not defined could be down to the runtime environment expecting ES Modules but the file wants CommonJS. Could be related to the introduction of "type": "module" to the package.json when logging was added.

kestra-io/libs@c7e0e74#diff-32d0752e48631d28147a6d14525fd9e8bdc58f81823a5d476ded9633b3d7c220R21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/backend Needs backend code changes area/plugin Plugin-related issue or feature request bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

3 participants