Question regarding external libraries with the jsPsych builder (i get errors) #2358
-
Hello, This is how i proceeded: command
JS (i only addead the import statement for knex.js) /**
* @title TESTING
* @description hihi
* @version 0.1.0
*
* @imageDir images
* @audioDir audio
* @videoDir video
* @miscDir misc
*/
import "../styles/main.scss";
import knex from 'knex';
import { initJsPsych } from "jspsych";
import FullscreenPlugin from "@jspsych/plugin-fullscreen";
import HtmlKeyboardResponsePlugin from "@jspsych/plugin-html-keyboard-response";
import PreloadPlugin from "@jspsych/plugin-preload";
/**
* @param {object} options
* @param {any} [options.input]
* @param {"development"|"production"|"jatos"} options.environment
* @param {{images: string[]; audio: string[]; video: string[];, misc: string[];}} options.assetPaths
*/
export async function run({ assetPaths, input = {}, environment }) {
const jsPsych = initJsPsych();
const timeline = [];
// Preload assets
timeline.push({
type: PreloadPlugin,
images: assetPaths.images,
audio: assetPaths.audio,
video: assetPaths.video,
});
// Welcome screen
timeline.push({
type: HtmlKeyboardResponsePlugin,
stimulus: "<p>Welcome to TESTING!<p/>",
});
// Switch to fullscreen
timeline.push({
type: FullscreenPlugin,
fullscreen_mode: true,
});
await jsPsych.run(timeline);
return jsPsych;
} When trying to run the experiment, I keep getting the following error (and a list of similar errors for other .js files): When I do not initialize jspsych-builder, knex works just fine. What did I do wrong? Thanks in advance for any help! I hope I did describe everything precise enough. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @jannisbosch,
The problem here is that knex.js is meant to be run on the server using Node.js, while the code you are writing in |
Beta Was this translation helpful? Give feedback.
Hi @jannisbosch,
if you take a closer look at the error message, it says
The problem here is that knex.js is meant to be run on the server using Node.js, while the code you are writing in
experiment.js
is bundled by webpack and executed by the client's browser. You'll need to keep the frontend and backend code separate (not only for security reasons)... In other words, any simple express + knex.js app would do for your backend. Whether that's a better solution than the PHP script is another question; a…