0

I would like to import a module who's file location is dynamic.

For example, I want a library dir to be prepended to the module name:

import foo from 'lib/'+'utils';

This apparently is not allowed, the syntax does not allow a calculated import name.

I have a similar situation with a single html file that imports arbitrary programs gotten from the query string as the variable "main", say. This also seems to fail:

import program from main; // var main = 'square-program';

How do I manage "dynamic" module names?

backspaces
  • 3,802
  • 6
  • 34
  • 58
  • 1
    The entire system of ES6 module imports and exports is designed to allow static analysis of dependencies, and for good reason cannot do what you want. `import` is not `require`. –  Jun 20 '15 at 17:23
  • 1
    @FelixKling: Uh, I want a es6 gold badge now :-) – Bergi Jun 20 '15 at 17:57
  • @Bergi: Working on it :D (I don't even have a bronze badge yet...) – Felix Kling Jun 20 '15 at 18:01

0 Answers0