0

I'm trying to export an Object from a .js file to another one. Actually I found many bits of help but with Node.js, and I'm not using it.

Do you think it's possible to do it without Node.js?

I've tried something :

//file1.js
var MyObject = {
property: value
};

export{MyObject};

//file2.js
import MyObject from 'file2.js';

This code gives me some errors :

  • Uncaught SyntaxError: Unexpected token 'export'
  • Uncaught SyntaxError: Cannot use import statement outside a module

EDIT : I've found another way to do what I was looking for without using the export method, thanks to the helpers !

1
  • Node.js supports ES6 modules with the experimental flag --experimental-modules Commented Aug 6, 2020 at 11:58

1 Answer 1

1
//file1.js
var MyObject = {
property: value
};

module.exports= MyObject;

//file2.js
var <Anyname>= require(<path>);
Sign up to request clarification or add additional context in comments.

1 Comment

It doesn't work for me, but I've found an other way to do what I was look for that doesn't need to export it, thanks for the help anyway !

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.