-1

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

tonitone120
  • 1,920
  • 3
  • 8
  • 25
  • Node.js supports both CommonJS and ES modules. But not at the same time. – GirkovArpa Aug 13 '20 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? – tonitone120 Aug 13 '20 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). – GirkovArpa Aug 13 '20 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: https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb – tonitone120 Aug 13 '20 at 23:35

1 Answers1

1

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

GirkovArpa
  • 4,427
  • 4
  • 14
  • 43