Using Several Js Files in Stackblitz with a Simple Js-Project

In StackBlitz it's possible to add another JS file(s) (besides index.js) but it seems that only index.js is actually being loaded. All the functions defined in other JS files created in the same (root) folder are just undefined when I try to call them within the index.js. I tried to 'activate' other files via HTML (<script src='./filename.js'> tag) but it didn't help. What am I doing wrong?

2 Answers

in index.js:

import {func} from './myscript.js';

In myscript.js:

exports.func = function(){...}
4

I have tried this and worked for me.

In index.js add below statement

import "./myscript.js";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest