title: Node.js: How to create ES6 module in C++
body: <p>This is the old example of creating a Node.js addon in C++:<br/>
  <a href="https://nodejs.org/api/addons.html" rel="nofollow noreferrer">https://nodejs.org/api/addons.html</a></p>
  <p>It can be built with node-gyp to a common JS module, which works fine with function 'require'. However, the compiled module can't be imported in .mjs file.</p>
  <p>This works fine: <code>node test.js</code></p>
  <pre><code>// test.js
  var m = require(&quot;./build/Release/addon&quot;);
  console.log(m.hello());
  </code></pre>
  <p>This doesn't: <code>node --experimental-modules test.mjs</code></p>
  <pre><code>// test.mjs
  import * as m from &quot;./build/Release/addon&quot;;
  console.log(m.hello());
  </code></pre>
  <p>The error is: <code>Error [ERR_MODULE_NOT_FOUND]: Cannot find module</code></p>
  <p>That C++ addon example page is for the old Node.js with common JS, any examples for C++ addon that can be built to be ES6 module to import in .mjs files?</p>