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
instead of use import, use require module
You are using ES6 syntax(
import
) over CommonJS(require
) syntax. In order to resolve your issue try usingrequire
instead ofimport
.In your 3D model javascript file:
In you other file use
require
: