0

I'm using the latest version of node.js and Chrome. Node.js still relies on CommonJS to do modules (exports and imports). The CommonJS page that was recommended to me actually says CommonJS is not suitable for client-side and to use ES modules instead. This makes me think I should use them for my websites that I'm creating. Is it possible to do this?

The errors I get when I try to are 'Uncaught SyntaxError: Unexpected token 'export' & unexpected token export' & 'Uncaught SyntaxError: Cannot use import statement outside a module.'

Here are the errors I get when I include type="module": enter image description here

4
  • Node.js supports both CommonJS and ES modules. But not at the same time. Commented Aug 13, 2020 at 23:06
  • @GirkovArpa can I get my question re-opened for the fact that I've already implemented the solution in the suggested article and it's not brought me success? Commented Aug 13, 2020 at 23:16
  • I can't open or close any questions. But you just solved your original problem using the type="module" approach. Now you have an entirely new problem which requires a new question (fair warning, it will probably get closed because it's been asked and answered before). Commented Aug 13, 2020 at 23:19
  • @GirkovArpa yes I've avoided being lazy and found the solution to host my webpage on a server with this Chrome extension: chrome.google.com/webstore/detail/web-server-for-chrome/… Commented Aug 13, 2020 at 23:35

1 Answer 1

2

Write <script type="module"> instead of <script>.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.