0

I'm currently debugging a local Node.js solution and I was wondering, is it possible to add an importmap to Node.js so I can use Import with resource name?

My import map:

<script type="importmap">
{
    "imports": {
        "options": "https://assets.sltech.no/SHARED/JS/OptionsFactory.js",
        "webrequest": "https://assets.sltech.no/SHARED/JS/WebRequest.js",
        "utility": "https://assets.sltech.no/SHARED/JS/Utility.js",
        "logger": "https://assets.sltech.no/SHARED/JS/Logger.js",
        "resources": "https://assets.sltech.no/SHARED/JS/ResourceAccessor.js"
    }
}
1

1 Answer 1

1

I am afraid, import map in nodejs are not natively supported yet.

however, you can do this by using alias in your package.json as

npm install module-alias

and detained aliases something like this

"_moduleAliases": {
        "yourAliasesKeyName": "./path/of/your/local/file.js"
//In your case 
        "options": "https://assets.sltech.no/SHARED/JS/OptionsFactory.js",
        "webrequest": "https://assets.sltech.no/SHARED/JS/WebRequest.js",
        "utility": "https://assets.sltech.no/SHARED/JS/Utility.js",
        "logger": "https://assets.sltech.no/SHARED/JS/Logger.js",
        "resources": "https://assets.sltech.no/SHARED/JS/ResourceAccessor.js"
}

after that, you can import the mentioned alias in your code:

import variable from "yourAliasesKeyName";

In your case

import options from 'options'; 
Sign up to request clarification or add additional context in comments.

1 Comment

ah great! I had issues with installing module-alias globally, the app found the module-alias module when I used --save.dev. I don't know if that causes any issues? When I tried to use it when installed as in the doc's it couldn't find the module

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.