javascriptclassbrowserexportimport-module

Javascript import myClass from '/myClass.js' does not work in browser


I want to import my classes from separate files while I am bulding with javascript. It is a very clean way to organize it; however, how do you do this? It appears that most browsers do not support this import function import Bullet from './bullet_class.js and in my bullet_class.js file: export default class Bullet { ... } I tried taking away the .js along with many other variations in the inport code but I think the problem is that some browsers don't support this. Does anyone know a work around or how to get this functionality working in the browser


Solution

  • Browsers don't support import and export directives directly and also module loading. So, you need to use some kind of module bundler or just NodeJS.