-2

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 2

0

instead of use import, use require module

Sign up to request clarification or add additional context in comments.

Comments

0

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()

1 Comment

Thanks for the details ! Unfortunately, I have tried and I get : "ReferenceError: require is not defined"...

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.