0

I want to import modules in a single line with ES6 modules, like it was done with the require syntax shown in the example.

var configApi = require('somemodule').config.get('services').api;

I've tried

import configApi from 'somemodule'.config.get('services').api;

and

import configApi from 'somemodule';
const api = confiApi.config.get('services').api;

but none of them have work.

Aleix
  • 117
  • 1
  • 7
  • The first thing you tried is clearly invalid syntax - the second looks like it should work ... depending on what `thethingsio-domain` exports and how it exports it - when you say "none of them have work" ... what happens? what even is `thethingsio-domain` ... it's not an NPM package – Jaromanda X Oct 28 '22 at 07:46
  • Check what is being exported by ```thethingsio-domain```. If it doesn't export ```configApi``` then you cannot import that. For more info see ```https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import``` – svarlitskiy Oct 28 '22 at 08:36
  • If the second doesn't work, try `import { config } from 'thethingsio-domain'; const { api } = config.get(…);` instead – Bergi Oct 28 '22 at 08:47

2 Answers2

0

I think what you are looking for is:

import * as configApi from "thethingsio-domain";
const api = confiApi.config.get('services').api;

but make sure you look at what is being exported by thethingsio-domain

svarlitskiy
  • 618
  • 5
  • 11
-1

Did you try using JavaScript dynamic importants.

import("/modules/my-module.js")
  .then((module) => {
    // do something 
  })
  .catch((err) => {
    console.error(err)
  });

For more information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import

Harshal Limaye
  • 172
  • 1
  • 3
  • 9