Skip to main content
adding missing quote
Source Link

On the script tag you are using to load the js in the browser you need to add the attribute

type="module"

It will look like the following:

<script type="module>type="module">
  import {addTextToBody} from './utils.mjs';

  addTextToBody('Modules are pretty cool.');
</script>

utils.mjs:

export function addTextToBody(text) {
  const div = document.createElement('div');
  div.textContent = text;
  document.body.appendChild(div);
}

This is if you are not using a bundler like webpack and working directly in the browser.

Source of code: https://jakearchibald.com/2017/es-modules-in-browsers/

On the script tag you are using to load the js in the browser you need to add the attribute

type="module"

It will look like the following:

<script type="module>
  import {addTextToBody} from './utils.mjs';

  addTextToBody('Modules are pretty cool.');
</script>

utils.mjs:

export function addTextToBody(text) {
  const div = document.createElement('div');
  div.textContent = text;
  document.body.appendChild(div);
}

This is if you are not using a bundler like webpack and working directly in the browser.

Source of code: https://jakearchibald.com/2017/es-modules-in-browsers/

On the script tag you are using to load the js in the browser you need to add the attribute

type="module"

It will look like the following:

<script type="module">
  import {addTextToBody} from './utils.mjs';

  addTextToBody('Modules are pretty cool.');
</script>

utils.mjs:

export function addTextToBody(text) {
  const div = document.createElement('div');
  div.textContent = text;
  document.body.appendChild(div);
}

This is if you are not using a bundler like webpack and working directly in the browser.

Source of code: https://jakearchibald.com/2017/es-modules-in-browsers/

Bounty Ended with 25 reputation awarded by CommunityBot

On the script tag you are using to load the js in the browser you need to add the attribute

type="module"

It will look like the following:

<script type="module>
  import {addTextToBody} from './utils.mjs';

  addTextToBody('Modules are pretty cool.');
</script>

enter image description hereutils.mjs:

export function addTextToBody(text) {
  const div = document.createElement('div');
  div.textContent = text;
  document.body.appendChild(div);
}

This is if you are not using a bundler like webpack and working directly in the browser.

sourceSource of imagecode: https://jakearchibald.com/2017/es-modules-in-browsers/

On the script tag you are using to load the js in the browser you need to add the attribute

type="module"

It will look like the following:

enter image description here

This is if you are not using a bundler like webpack and working directly in the browser.

source of image: https://jakearchibald.com/2017/es-modules-in-browsers/

On the script tag you are using to load the js in the browser you need to add the attribute

type="module"

It will look like the following:

<script type="module>
  import {addTextToBody} from './utils.mjs';

  addTextToBody('Modules are pretty cool.');
</script>

utils.mjs:

export function addTextToBody(text) {
  const div = document.createElement('div');
  div.textContent = text;
  document.body.appendChild(div);
}

This is if you are not using a bundler like webpack and working directly in the browser.

Source of code: https://jakearchibald.com/2017/es-modules-in-browsers/

Source Link

On the script tag you are using to load the js in the browser you need to add the attribute

type="module"

It will look like the following:

enter image description here

This is if you are not using a bundler like webpack and working directly in the browser.

source of image: https://jakearchibald.com/2017/es-modules-in-browsers/