A question about scoped imports

I’ve made some tests regarding scoped importing, and it seems like Meteor supports importing files directly from another package. For instance, if I have a package test-export, which has a file test.js, which in turn does export default 'Hello World!', I can, in another package which depends on test-export, perform import test from 'meteor/test-export/test.js'; console.log(test); and receive Hello World! in my console.

I could not find something official about this in meteor documentation. Is this feature “stable” and is safe to use long-term? Or is this some sort of a side effect? @benjamn maybe you can tell something specific about this?

Yes - import has been supported since 1.3:

Non-top-level import has been available since 1.3.3:

Yes, importing specific files from other packages is a deliberate and reliable feature. It even works with dynamic import(...) (try Meteor 1.5-beta.8). We may at some point allow packages to prevent some files from being imported, using an API in package.js, but we haven’t seen an urgent need for that yet.

Note that this behavior is very similar to the way Node/npm work when you require("babel-runtime/helpers/typeof") (for example). The package.json file is ignored (in fact babel-runtime has no package.json file) because you’re asking for a specific file.

1 Like