import-esm-sync

import ESModule synchronously

Usage no npm install needed!

<script type="module">
  import importEsmSync from 'https://cdn.skypack.dev/import-esm-sync';
</script>

README

import-esm-sync

This package can import ESModules synchronously by calling Node.js event loop.
Of course, this can also import CommonJS, but I recommend using the require function.

Usage

import a ESModule

const importSync = require('import-esm-sync');
const { default: fetch } = importSync('node-fetch');

import a local ESM JavaScript file

const importSync = require('import-esm-sync');
const abc = importSync('./abc.mjs');