-
Notifications
You must be signed in to change notification settings - Fork 545
Open
Description
Version info:
Artillery: 2.0.14
Node.js: v20.9.0
OS: linux
Running this command:
artillery run test.yml
I expected test to run successfully, but
Instead, this happened:
⠋ /<...>/node_modules/@artilleryio/int-core/lib/runner.js:97
script.config.processor = require(processorPath);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /<...>/processor.js from /<...>/node_modules/@artilleryio/int-core/lib/runner.js not supported.
Instead change the require of processor.js in /<...>/node_modules/@artilleryio/int-core/lib/runner.js to a dynamic import() which is available in all CommonJS modules.
at loadProcessor (/<...>/node_modules/@artilleryio/int-core/lib/runner.js:97:33)
Files being used:
[test.yml]
config:
# ...
processor: 'processor.js' # pointed to a ES Module
My project has ES modules with *.js extension and type="module" set in the package.json. According to https://nodejs.org/api/packages.html#determining-module-system it is a valid way of specifying ES module files.
Problem arises from the following code in packages/core/lib/runner.js:
async function loadProcessor(script, options) {
const absoluteScriptPath = path.resolve(process.cwd(), options.scriptPath);
if (script.config.processor) {
const processorPath = path.resolve(
path.dirname(absoluteScriptPath),
script.config.processor
);
if (processorPath.endsWith('.mjs')) { // <- this check is causing to divert to incorrect path
const exports = await import(processorPath);
script.config.processor = Object.assign(
{},
script.config.processor,
exports
);
} else {
// CJS (possibly transplied from TS)
script.config.processor = require(processorPath);
}
}
return script;
}
Probable fix could be simply removing the conditional and always attempt to import(module) as Node.js should be able to determine the module format and import it correctly for both CJS and ESM.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels