skip to Main Content

I am trying to develop an Excel addin that would use Three.js.
For that, I have several files :

  • Home.html, my main html
  • 3dModel.js, the script using three to create and display my 3d model
  • Home.js, my main Excel addin script

Everything is working in both js scripts on their own, but I would like to call a function funct1(), defined in 3dModel.js inside Home.js.
Is this possible ?

I have tried :

// 3dModel.js
export funct1(){
    console.log("test");
}

// Home.js
import { funct1 } from './3dModel.js';
funct1();

But I get "Uncaught SyntaxError: Cannot use import statement outside a module" whereas I am calling both my scripts as modules :

<script type="module" src="./3dModel.js"></script>
<script type="module" src="./Home.js"></script>

What am I missing ? Thanks a lot for your help, I am still a beginner !

2

Answers


  1. instead of use import, use require module

    Login or Signup to reply.
  2. You are using ES6 syntax(import) over CommonJS(require) syntax. In order to resolve your issue try using require instead of import.

    In your 3D model javascript file:

    var funct1 = function(value) {
      console.log("test");
    };
    
    module.exports.funct1 = funct1;
    

    In you other file use require:

    var 3dModel = require('./3dModel');
    3dModel.funct1()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search