-
Notifications
You must be signed in to change notification settings - Fork 6
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
Module error when using Javascript #9
Comments
I am encountering an error when attempting to run the following Kestra flow, which is designed to execute a Node.js script using the @kestra-io/libs library within a Docker container.
error: 2024-10-14 10:00:57.059 npm notice New minor version of npm available! 10.8.3 -> 10.9.0 |
Still seems like an issue in 0.20: kestra-io/plugin-scripts#192 |
@wrussell1999 @anna-geller, let's continue the conversation here from kestra-io/plugin-scripts#192. |
First of all, the approach in the the current PR to resolve the issue has some potential problems and doesn't fully address the issue here or provide a future-proof solution. Mixing Module FormatsThe solution proposed attempts to provide support for both CommonJS and ESM modules. Changing file extensions to
Package.json ConfigurationThe issue stems from setting Compatibility with Previous VersionsBy requiring developers to specify the @kestra-io/[email protected] version explicitly, you're tying compatibility to a specific library version. This approach has the following issues:
Testing and QA ProcessThe testing process for this is lacking as it doesn't highlight the changes made working with an external project:
|
fix: Removed my username from author
I keep getting error when using the Javascript module and using
type: io.kestra.plugin.scripts.node.Script
beforeCommands:
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
containerImage: node:slim
warningOnStdErr: false
logLevel: DEBUG
script: |
const Kestra = require ('@kestra-io/libs');
here is the error
2024-10-05 15:27:15.985Using task runner 'io.kestra.plugin.scripts.runner.docker.Docker' 2024-10-05 15:27:19.214Starting command with container id 3dbbecd088494911a2f47b8093bf5a3c45b8f0afc0e973790788d2e9d9c447f0 [/bin/sh -c set -e npm i @kestra-io/libs node /tmp/kestra-wd/tmp/1ZqEAZLo7y9Y3IJlth2u32/4712153262335601460.js] 2024-10-05 15:27:20.722 2024-10-05 15:27:20.722added 1 package in 1s 2024-10-05 15:27:20.724npm notice New minor version of npm available! 10.8.3 -> 10.9.0 2024-10-05 15:27:20.724npm notice 2024-10-05 15:27:20.724npm notice To update run: npm install -g [email protected] 2024-10-05 15:27:20.724npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.9.0 2024-10-05 15:27:20.725npm notice 2024-10-05 15:27:20.762/tmp/kestra-wd/tmp/1ZqEAZLo7y9Y3IJlth2u32/4712153262335601460.js:315 2024-10-05 15:27:20.763at TracingChannel.traceSync (node:diagnostics_channel:315:14) 2024-10-05 15:27:20.763code: 'ERR_REQUIRE_ESM' 2024-10-05 15:27:20.763Instead either rename index.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 /tmp/kestra-wd/tmp/1ZqEAZLo7y9Y3IJlth2u32/node_modules/@kestra-io/libs/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead). 2024-10-05 15:27:20.763index.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. 2024-10-05 15:27:20.763at Object.<anonymous> (/tmp/kestra-wd/tmp/1ZqEAZLo7y9Y3IJlth2u32/4712153262335601460.js:1:16) { 2024-10-05 15:27:20.763} 2024-10-05 15:27:20.763undefined 2024-10-05 15:27:20.763
I tried using the require and import ES6 syntax and both did not work.
here is the error when using import
2024-10-05 15:29:19.621added 1 package in 846ms 2024-10-05 15:29:19.623npm notice 2024-10-05 15:29:19.623npm notice New minor version of npm available! 10.8.3 -> 10.9.0 2024-10-05 15:29:19.623npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.9.0 2024-10-05 15:29:19.623npm notice To update run: npm install -g [email protected] 2024-10-05 15:29:19.623npm notice 2024-10-05 15:29:19.674Reparsing as ES module because module syntax was detected. This incurs a performance overhead. 2024-10-05 15:29:19.674To eliminate this warning, add "type": "module" to /tmp/kestra-wd/tmp/1HNjMnlv4YbIleA7jXXEfV/package.json. 2024-10-05 15:29:19.674(Use
node --trace-warnings ...to show where the warning was created) 2024-10-05 15:29:19.674(node:18) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///tmp/kestra-wd/tmp/1HNjMnlv4YbIleA7jXXEfV/2272223555352646281.js is not specified and it doesn't parse as CommonJS. 2024-10-05 15:29:19.679^^^^^^ 2024-10-05 15:29:19.679at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:483:26) 2024-10-05 15:29:19.679SyntaxError: The requested module '@kestra-io/libs' does not provide an export named 'Kestra' 2024-10-05 15:29:19.679at async ModuleJob.run (node:internal/modules/esm/module_job:254:5) 2024-10-05 15:29:19.679file:///tmp/kestra-wd/tmp/1HNjMnlv4YbIleA7jXXEfV/2272223555352646281.js:1 2024-10-05 15:29:19.679import {Kestra} from '@kestra-io/libs'; 2024-10-05 15:29:19.679at ModuleJob._instantiate (node:internal/modules/esm/module_job:171:21) 2024-10-05 15:29:19.683Node.js v22.9.0
Since I was following Kestra documentation for JavaScript plugin npm will default to the latest package which is currently 0.20.0-SNAPSHOT
The temporary fix is to use the previous version in npm explicitly - "npm i @kestra-io/[email protected]"
To fix it, it looks like the code should be updated to ES6 syntax, remove type:"module" from the package.json, or rename index.js to index.cjs in order to continue using CommonJS with "type":"module" in package.json
The text was updated successfully, but these errors were encountered: