1

I've written ES module which imports other modules and exports some stuff. Now I want to use the same module in Node. (share the same file)

Is there any universal way how to deal with differences e.g. "import" vs "require" and "export" vs "exports"? I want solution without browserify or webpack, just some hack to make it work in node and in browser too.

I can make the "export" part, I don't know if there is any hack to make the "import/require" part.

user2106769
  • 445
  • 5
  • 15
  • 1
    Here's how to use `import` / `export` with node: https://stackoverflow.com/a/39436580/5734311 and here's how to use it in a browser: https://stackoverflow.com/questions/48211891/import-functions-from-another-js-file-javascript/48212558#48212558 –  Jan 06 '20 at 15:23
  • 1
    Node supports ESM modules with the [`--experimental-modules`](https://nodejs.org/docs/latest-v12.x/api/esm.html#esm_enabling) flag in node 12 LTS. – zero298 Jan 06 '20 at 15:24

0 Answers0