title: How to properly expose subpaths in package.json using the ”exports” key?
body: <p>I’ve released a NPM package which is a plugin for a framework where only the main entry of my package.json is needed for usage in the framework and its environment. I also want to be able to use a subpath of the plugin in order for users to be able to use the plugin outside of this framework as well, which will require that the main entry point is never initialized as there are framework specific dependencies used there which I don't want to initialize when using this plugin outside of the framework.</p>
  <p>My project structure looks like this:</p>
  <pre><code>.
  ├── index.js
  ├── submodule.js
  └── package.json
  </code></pre>
  <p>Source code for the sake of this example looks like this:</p>
  <pre class="lang-js prettyprint-override"><code>// index.js
  export default function () {
    return &quot;foo&quot;;
  }
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>// submodule.js
  export default function () {
    return &quot;bar&quot;;
  }
  </code></pre>
  <pre class="lang-json prettyprint-override"><code>// package.json
  {
    &quot;name&quot;: &quot;my-package&quot;,
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;description&quot;: &quot;&quot;,
    &quot;main&quot;: &quot;index.js&quot;,
    &quot;type&quot;: &quot;module&quot;,
    &quot;exports&quot;: {
      &quot;.&quot;: &quot;./index.js&quot;,
      &quot;./submodule&quot;: &quot;./submodule.js&quot;
    },
    &quot;scripts&quot;: {
      &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;
    },
    &quot;keywords&quot;: [],
    &quot;author&quot;: &quot;&quot;,
    &quot;license&quot;: &quot;MIT&quot;
  }
  </code></pre>
  <p>According to Node.js <a href="https://nodejs.org/api/packages.html#packages_subpath_exports" rel="nofollow noreferrer">documentation</a> on this matter, this setup should allow me to use my package like this:</p>
  <pre class="lang-js prettyprint-override"><code>import myPackage from ’my-package’
  import mySubModule from ’my-package/submodule’
  </code></pre>
  <p>In order to be able to test my package locally I run <code>npm link</code> in the project root of my npm package and then in another project i run <code>npm link my-package</code>. Now that I try to run the project (using parcel-bundler) that imports <code>my-package</code> and <code>my-package/submodule</code> like in the example above I get the following exception:</p>
  <pre><code>Cannot resolve dependency 'my-package/submodule'
  </code></pre>
  <p>I'm using NVM with Node v.12.18.4 and NPM v.7.15.0. I have also tried with Node v.14.17.0 but the issue persists. What am I missing?</p>