Is there any good way to load a module elegantly (where the IDE can suggest or go into the file) using dynamic path or start from the root directory to import a module?
import * as Q from 'q';
import * as loopback from 'loopback';
import datasources from '../../../datasources.json';
import app from '../../../server';
import {ApiError, ValidationError, DatabaseError} from'../../../utils/error-handlers';
node_modules
to your preferred default load location? Use a flatter directory structure? – Redintegrationimport app from '/server'
? Your module loader is responsible for resolving those strings to modules. Check its docs about support of paths, and maybe file a feature request. – Brotherimport ... from 'moduleIdentifier';
. It does not care whatmoduleIdentifier
is. The module loader cares. In case of NodeJS, the module loader interprets the identifiers as paths or names. Which syntax you use (CommonJS or ES6) is irrelevant. If the question is whether there is specific syntax or support in ES6 then the answer is: no. The duplicate was absolutely relevant because it explained how to solve this in NodeJS (no matter the synax). – Nymphetbabel/register
hack?). Anything mentioned here would work: https://mcmap.net/q/87818/-how-can-i-make-node-js-39-require-39-absolute-instead-of-relative . Why shouldn't it work with ES6 syntax? After all, Babel simply compiles to CommonJS (if you want to execute it in a Node.js environment). Anything you mentioned in your first comment is pretty much independent of the specific import syntax. – Nymphet