Folder management in gatling-js

Gatling version:
Gatling flavor: javascript
Gatling build tool: npm

Hi, currently I’m trying to set up my gatling js project following this structure (similar to java)

src
 -> api
    --> reqresApi.js
 -> scenario
    --> reqresScenario.js
 -> simulation
    --> reqresSimulation.js

With the content separate for each file as following:
reqresApi.js

import { exec, http} from '@gatling.io/core';

export const reqresDemo = exec(
    http('ClientBulkReportingMedium')
        .get('https://reqres.in/api/users?page=2')
        .requestTimeout(300000)
);

reqresScenario.js

import { scenario } from '@gatling.io/core';
import { reqresDemo } from '../api/reqresApi.js';

export const UserBehaviorReqres = scenario('Users')
        .exec(reqresDemo);

reqresSimulation.js

import { atOnceUsers, simulation } from '@gatling.io/core';
import * as reqresScenario from '../scenario/reqresScenario.js';


export default simulation((setUp) => {
    setUp(
        reqresScenario .UserBehavior.injectOpen(atOnceUsers(1)),
    );
});

I tried to trigger the test running this command

npx gatling run --sources-folder src/simulation

Then I got this error log, this time still type undefined

Bundling a Gatling simulation with options:
 - sourcesFolder: src/simulation
 - bundleFile: target/bundle.js
 - typescript: false
Running a Gatling simulation with options:
 - simulation: reqresSimulation
 - bundleFile: target/bundle.js
 - resourcesFolder: resources
 - resultsFolder: target/gatling
13:42:11.936 [ERROR] i.g.a.Gatling$ - Run crashed
org.graalvm.polyglot.PolyglotException: TypeError: undefined is not a function
        at <js>.:=>(bundle.js:2073)
        at <js>.:program(bundle.js:1)
        at org.graalvm.polyglot.Context.eval(Context.java:402)
        at io.gatling.js.JsSimulationHelper.loadSimulation(JsSimulationHelper.java:64)
        at io.gatling.js.JsSimulation.<init>(JsSimulation.java:38)
        at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
        ... 9 common frames omitted
Wrapped by: java.lang.reflect.InvocationTargetException: null
        at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:74)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:501)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:485)
        at io.gatling.app.SimulationClass$JavaScript.params(SimulationClass.scala:57)
        at io.gatling.app.Runner.load(Runner.scala:72)
        at io.gatling.app.Runner.run(Runner.scala:55)
        at io.gatling.app.Gatling$.start(Gatling.scala:83)
        at io.gatling.app.Gatling$.fromArgs(Gatling.scala:46)
        at io.gatling.app.Gatling$.main(Gatling.scala:40)
        at io.gatling.app.Gatling.main(Gatling.scala)
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:74)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:501)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:485)
        at io.gatling.app.SimulationClass$JavaScript.params(SimulationClass.scala:57)
        at io.gatling.app.Runner.load(Runner.scala:72)
        at io.gatling.app.Runner.run(Runner.scala:55)
        at io.gatling.app.Gatling$.start(Gatling.scala:83)
        at io.gatling.app.Gatling$.fromArgs(Gatling.scala:46)
        at io.gatling.app.Gatling$.main(Gatling.scala:40)
        at io.gatling.app.Gatling.main(Gatling.scala)
Caused by: org.graalvm.polyglot.PolyglotException: TypeError: undefined is not a function
        at <js>.:=>(bundle.js:2073)
        at <js>.:program(bundle.js:1)
        at org.graalvm.polyglot.Context.eval(Context.java:402)
        at io.gatling.js.JsSimulationHelper.loadSimulation(JsSimulationHelper.java:64)
        at io.gatling.js.JsSimulation.<init>(JsSimulation.java:38)
        at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
        ... 9 more
C:\projects\gatling-js-demo-main\javascript\node_modules\@gatling.io\cli\target\java.js:33
                reject(Error("Gatling process finished with code " + code));
                       ^

Error: Gatling process finished with code 1
    at ChildProcess.<anonymous> (C:\projects\gatling-js-demo-main\javascript\node_modules\@gatling.io\cli\target\java.js:33:24)
    at ChildProcess.emit (node:events:524:28)
    at maybeClose (node:internal/child_process:1101:16)
    at ChildProcess._handle.onexit (node:internal/child_process:304:5)

Node.js v22.13.1

Does Gatling js support for this usage ?

Hello, in reqresApi.js, http should be imported from @gatling.io/http, not core:

import { exec } from '@gatling.io/core';
import { http } from '@gatling.io/http'; 

I’m wondering why the js runtime is letting you do that, I’ll investigate.

Hi,
I have separate the import as you said, still same error log :frowning:

Oh and you call reqresScenario.UserBehavior in reqresSimulation.js file but the export is named UserBehaviorReqres.

Hi @notdryft , after your suggestion I did some following changes over here, and it works:
Before:

import { exec, http, status, ElFileBody } from '@gatling.io/core';

Separate from exec and http

import { exec, ElFileBody } from '@gatling.io/core';
import { http, status } from '@gatling.io/http';

Much Appreciate, Thank you !