Today I will introduce the last major prerequisite to adopt Rspack in your Meteor app: transforming nested imports into a standard style.
Nested imports are a Meteor-specific bundler feature not supported by standard tools. They come from the reify package and allow you to place import
statements inside nested blocks (ifs, function bodies, etc.), deferring evaluation of the imported code (why nested imports?). In standard JavaScript you should instead use require
or dynamic import
(which can also split your bundle).
Example of a nested import:
// import { a as b } from "./c"; // root import
if (condition) {
import { a as b } from "./c"; // nested import
console.log(b);
}
Don’t confuse nested imports with dynamic imports (await import(...)
). Dynamic imports are a modern standard for bundlers, letting you split bundles and defer loading safely.
Migration
To identify and fix nested imports in your project, use verbose mode in Meteor 3.3’s modern transpiler. Enable it with:
"meteor": {
"modern": {
"transpiler": {
"verbose": true
}
}
}
When you run your app, [Transpiler]
logs will show each file. Focus on (app)
files that fail with messages like:
Error: 'import' and 'export' cannot be used outside of module code
Fix nested imports by moving them to the top of the file, or by replacing them with require
or dynamic import
.
You can skip migrating (package)
code with nested imports. Meteor packages are still handled by the Meteor bundler in Rspack integration, but your app code is fully delegated to Rspack and must use standard syntax.
Backwards compatibility
While backwards compatibility was straightforward for the SWC integration in Meteor 3.3, achieving the same for Rspack in Meteor 3.4 is harder. In Meteor 3.3, we had a fallback mechanism using Babel+Reify per file, which SWC couldn’t handle but still worked at a file level. With Rspack, the integration is at the bundle level: the entire app code is processed by a modern bundler that not only parses files individually but also links them into a single distributable. Since Reify has its own way of linking modules, ensuring compatibility with a modern bundler has been difficult.
In the future, we might explore solutions, but our focus is on moving Meteor forward with a modern-first approach. For nested imports, there’s little reason to keep them today since standard alternatives exist and bring clear benefits with modern bundlers.
Remember, Rspack integration is optional. You can continue using Meteor’s bundler and still benefit only from Meteor 3.3 optimizations if you prefer.
Please answer the following question so we can assess how prepared your project is for nested imports migrations.
When using verbose mode, do you have nested imports in your <app>
code?
- Yes, I have nested imports, but I will migrate them
- My code is standardized and ready to integrate Rspack
- Regardless of nested imports, I prefer to keep Meteor specifics and will skip Rspack