Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Directory import not supported

Before now I was using CommonJS and module-alias but I want to move over to ES modules and switch to the natively supported import mappings, so I refactored to this in my package.json:

{
   "imports": {
      "#http/*": "./http/",
      "#cloud/*": "./cloud/",
      "#constants": "./constants"
    } 
}

However when I do this in my server.js:

import APIClient from '#http/apiClient';

I get the following error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Directory import /Users/me/sampleApp/http/ is not supported

This was working perfectly fine with module-alias what am I doing wrong now?

>Solution :

With these subpath patterns, you need to specify the wildcard on both sides, and the extension too:

{
  "imports": {
    "#http/*": "./http/*",
    "#cloud/*": "./cloud/*",
    "#constants": "./constants.js"
  } 
}
import APIClient from '#http/apiClient.js';

* maps expose nested subpaths as it is a string replacement syntax only.

All instances of * on the right hand side will then be replaced with this value, including if it contains any / separators.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading