node_modules 的 es6 等价物是什么?

What is the es6 equivalent of node_modules?

我习惯了 require 但我正在玩 es6 模块。我决定更改我的目录结构,这意味着我必须去更改所有导入语句(import thing from "../thing" 变成 import thing from "../../thing" 等)。

我不得不经历并改变很多。使用 node_modules,这绝不是问题。

您是否总是必须在 es6 模块中指定路径,或者是否有某种 system/order-of-operation 用于查找模块?

在 ES6 中没有直接等同于 node_modules,这意味着不能从预定义的目录中按名称导入模块。不存在这样的目录,因此模块必须通过路径导入。

ES6 模块的做法是将它们放在一个扁平的(大概)目录结构中,就像您使用所有 ../thing 更改创建的目录结构一样。

顺便说一句,bundlers 虚拟化了这个过程,这就是为什么你可能不习惯看到 import '../thing'

如果您想同时支持 ES6 和 Node.js 风格的模块,以及平面和 node_modules 目录结构,请查看此 example and it's introductory article.