-
Notifications
You must be signed in to change notification settings - Fork 49
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
VAS Plugin Error with webpack #26
Comments
@bjoluc any thoughts on this one? I'm guessing there is some config needed because the VAS plugin is not using the TS template, and that we may want to adjust the package build for this scenario. |
@d-bohn The VAS plugin is meant to be included in a script tag and works with global variables, most notably the import jsPsychHtmlVasResponse from "imports-loader?type=commonjs&imports=single|jspsych|jsPsychModule!exports-loader?type=commonjs&exports=single|jsPsychHtmlVasResponse!@jspsych-contrib/plugin-html-vas-response"; like any other core plugin.
@jodeleeuw We might be able to add an extra build step that creates an ES/commonjs module based on the IIFE file. But that would be pretty hacky and nothing I'd like to maintain. Maybe mention the imports-loader exports-loader workaround somewhere instead? I just put together a generic webpack config extension I think I'll add to jsPsych builder (@d-bohn you can simply apply this to your webpack import { readFileSync } from "fs";
// Transform IIFE plugins from `@jspsych-contrib` to modules using `imports-loader` and `exports-loader`
config.module.rules.push({
test: (resource) => resource.includes("/@jspsych-contrib/plugin-"),
use: (info) => {
if (info.descriptionData.main) {
// The `main` field is not set in the IIFE plugin template, so we consider everything with
// a `main` field non-IIFE and ignore it here.
return [];
}
// Extract the global variable name of the plugin
const pluginVarName = /^var ([a-zA-Z]+) = \(function/m.exec(
readFileSync(info.resource).toString()
)[1];
return [
"imports-loader?type=commonjs&imports=single|jspsych|jsPsychModule",
`exports-loader?type=commonjs&exports=single|${pluginVarName}`,
];
},
}); |
That works for me; thanks for the clarification! |
…ch-contrib` See jspsych/jspsych-contrib#26 for the motivation behind this
Hi folks, would it be helpful for me to simply rewrite the code using the TS template? I would be happy to if it would make it more usable. |
@kinleyid That's not directly necessary given the workaround - but it would sure be great! |
Hello,
I was excited to see that someone contributed a VAS plugin for jsPsych. I'd very much like to try this plugin in one of my experiments, however, when I try to use it as a drop-in replacement for
survey-likert
(with the appropriate parameters) it throws an error:Uncaught ReferenceError: jsPsychModule is not defined
.I downloaded the plugin using npm and compiled the experiment with webpack. The experiment compiles, but during runtime throws the error above. I'm confident that the error is related to the VAS plugin as the experiment works perfectly fine with the likert scale plugin, however, when using the VAS plugin the error occurs.
Any thoughts on how to remedy the issue so I can play around with the plugin would be appreciated!
The text was updated successfully, but these errors were encountered: