In defense of static imports

Mike, thanks for the thoughtful response!

Regarding disambiguation between NPM and Observable cells — I covered this at the end of the post, but let me clarify: I think Observable should NOT support NPM resolution with static import syntax at all:

import Delatin from 'delatin' /* ERROR — URL or Observable ID expected */
import Delatin from 'https://unpkg.com/delatin' /* External import */
import {legend} from '@d3/color-legend' /* All non-URLs are treated as cell imports */

This would get rid of all disambiguation without the need for any prefixes. It also doesn’t break compatibility because you only add support for something that currently errors (static import from a url) without changing any other behavior (require, dynamic import etc.).

You can also draw a parallel between Node and Observable:

  • In Node, if require is given a relative or absolute path, it resolves to it; otherwise it looks in node_modules
  • In Observable, if static import is given an URL, it would resolve to it; otherwise it would look among Observable cells
2 Likes