migrate-to-meteor-3
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMigrate a Meteor 2.x application to Meteor 3.x
将Meteor 2.x应用迁移至Meteor 3.x
Meteor 3 removed Fibers. Server-side Mongo APIs are async. The module system
enforces strict mode. Client reactivity inside async code needs care.
Atmosphere packages often need forking or replacement. Approach the migration
in phases. Do not flip the framework version flag first.
Meteor 3移除了Fibers。服务器端Mongo API改为异步模式。模块系统强制启用严格模式。异步代码中的客户端响应性需要特别处理。Atmosphere包通常需要分叉或替换。建议分阶段进行迁移,不要先切换框架版本标志。
Recommended strategy
推荐策略
- Update the project to the latest 2.x release.
- Run the app with . The console logs every sync-API call that needs an async sibling, giving you a to-do list before the framework flip.
WARN_WHEN_USING_OLD_API=true meteor run - Migrate server-side sync Mongo calls to siblings while still on 2.x. Trace each changed function through every server-side caller: await where the caller consumes the value, forward Promises deliberately, and restructure sync-only boundaries. Stop only at an async-capable framework boundary. See
*Asyncandreferences/async-rewrites.md. A community jscodeshift codemod automates the easy cases, but it misses non-standard collection imports (for example,references/call-vs-callAsync.md). Review the diff by hand, then audit callback Promise ownership and collection argument shapes.meteor/<publisher>:collections - Audit Atmosphere packages. Find replacements or fork outdated ones;
pin . See
api.versionsFrom(['2.x', '3.0']). Savereferences/package-triage.mdand npm lockfile checkpoints so package-major changes remain distinguishable from Meteor..meteor/versions - Upgrade to Meteor 3.x.
- Sweep implicit globals; rewrite to or
const/export. Seeimport.references/module-system.md - Audit Blaze helpers and blocks for lost reactivity after
Tracker.autorun. Seeawait.references/client-reactivity.md - Replace iterators that contain (
await,forEach,map) withfilterorfor...of. SeePromise.all.references/js-iterators.md - Audit publications using internal cursor APIs (, manual
_cursorDescription) and framework handlers that read invocationsub.added. Both synchronous and async publish handlers may return cursors; keep cursor transforms synchronous and use ordinary functions when Meteor must bindthis. When a package patchesthiswith anMeteor.publish, scopeEnvironmentVariableat the wrapper's top level, not inside the invoked handler. Verify invocation context before and afterpublish.call. Seeawaitandreferences/publications.md.references/other-breaking-changes.md - For TypeScript projects, install and update
zodern:types. Seetsconfig.json.references/typescript-migration.md - For React projects, decide whether to adopt the Suspense-aware
import. See
react-meteor-data, then usereferences/react-migration.mdfor current hook, scaffold, and build guidance.meteor-react
- 将项目更新至最新的2.x版本。
- 使用命令运行应用。控制台会记录所有需要替换为异步等效API的同步API调用,为你在切换框架版本前提供一份待办事项清单。
WARN_WHEN_USING_OLD_API=true meteor run - 仍在2.x版本时,将服务器端同步Mongo调用迁移至等效方法。追踪每个修改函数的所有服务器端调用者:在调用者消费值的地方添加await,有意传递Promise,并重构仅支持同步的边界。仅在支持异步的框架边界处停止操作。详见
*Async和references/async-rewrites.md。社区提供的jscodeshift代码转换工具可自动化处理简单场景,但会遗漏非标准集合导入(例如references/call-vs-callAsync.md)。需手动审查差异,然后审核回调Promise的所有权和集合参数格式。meteor/<publisher>:collections - 审核Atmosphere包。寻找替代包或分叉过时的包;设置。详见
api.versionsFrom(['2.x', '3.0'])。保存references/package-triage.md和npm锁文件检查点,以便区分包的重大变更与Meteor本身的变更。.meteor/versions - 升级至Meteor 3.x。
- 清理隐式全局变量;将其重写为或使用
const/export。详见import。references/module-system.md - 审核Blaze助手和块,检查
Tracker.autorun之后是否丢失响应性。详见await。references/client-reactivity.md - 将包含的迭代器(
await、forEach、map)替换为filter或for...of。详见Promise.all。references/js-iterators.md - 审核使用内部游标API(、手动
_cursorDescription)的发布内容,以及读取调用上下文sub.added的框架处理器。同步和异步发布处理器都可以返回游标;保持游标转换为同步模式,当Meteor必须绑定this时使用普通函数。当某个包使用this修补EnvironmentVariable时,在包装器的顶层作用域调用Meteor.publish,而不是在调用的处理器内部。验证publish.call前后的调用上下文。详见await和references/publications.md。references/other-breaking-changes.md - 对于TypeScript项目,安装并更新
zodern:types。详见tsconfig.json。references/typescript-migration.md - 对于React项目,决定是否采用支持Suspense的导入。详见
react-meteor-data,然后使用references/react-migration.md获取当前钩子、脚手架和构建相关指南。meteor-react
Symptom router
症状路由表
| Symptom | Reference |
|---|---|
| |
| |
Downstream caller receives or reads from a | |
| Cron, hook, timer, or event callback drops a Promise | |
Read method receives | |
| |
| |
| |
| Template renders, no data, Minimongo empty | |
| Iron Router controller silently does not run | |
| |
| Page renders but live data never updates | |
Blaze helper returns a | |
Cursor | |
| |
Method or publication loses | |
| Atmosphere package fails to resolve or build | |
| |
Middleware on | |
| Route uses an unnamed wildcard after Meteor 3.1 | |
| |
Patched publication loses | |
| |
| |
"Cannot enlarge memory array" during | |
External callback lost | |
Monkey-patched | |
| |
| |
| 症状 | 参考文档 |
|---|---|
| |
| |
下游调用者接收或读取 | |
| Cron、钩子、定时器或事件回调丢弃Promise | |
读取方法接收 | |
| |
| |
启动时出现 | |
| 模板渲染但无数据,Minimongo为空 | |
| Iron Router控制器静默未运行 | |
Blaze中 | |
| 页面已渲染但实时数据从未更新 | |
Blaze助手返回 | |
游标 | |
| |
方法或发布内容丢失 | |
| Atmosphere包解析或构建失败 | |
含 | |
| |
| Meteor 3.1之后路由使用未命名通配符 | |
| |
修补后的发布内容丢失 | |
| |
| 控制台出现“Method stub (X) took too long”警告 | |
| |
外部回调丢失 | |
猴子补丁的 | |
TypeScript中 | |
| |
Anti-patterns
反模式
- Do not run first. Async-convert and package-triage on 2.x first.
meteor update --release=3 - Do not global-replace with
findOne. Many callers need rewriting, not justfindOneAsync.await - Do not mechanically rewrite client Minimongo calls to async. Both APIs work
on the client. Prefer sync calls in naturally synchronous Blaze and Tracker
code; use async calls in shared or already-async flows. Wrap reactive reads
after an with
await.Tracker.withComputation - Do not rely on Iron Router controller naming-convention lookup. Pass
explicitly on every route.
controller: - Do not mix and
awaitin the same function. Pick one..then() - Do not assume implicit globals work. Every top-level identifier in 3.x
must be ,
const, orlet-ed.export - Do not invent async replacements. remains synchronous inside methods and publications; there is no
Meteor.userId().Meteor.userIdAsync() - Do not use an arrow as a method or publication handler when it reads
framework-bound . An arrow ignores the invocation context Meteor supplies.
this - Do not rewrite or
api.addFilesonly because the app moved to Meteor 3. They remain supported for Atmosphere packages.api.export
- 不要先运行。应先在2.x版本完成异步转换和包梳理。
meteor update --release=3 - 不要全局将替换为
findOne。许多调用者需要重写,而不仅仅是添加findOneAsync。await - 不要机械地将客户端Minimongo调用重写为异步。两种API在客户端都可用。在自然同步的Blaze和Tracker代码中优先使用同步调用;在共享或已异步的流程中使用异步调用。在之后的响应式读取需用
await包裹。Tracker.withComputation - 不要依赖Iron Router控制器的命名约定查找。在每个路由上显式传递参数。
controller: - 不要在同一个函数中混合使用和
await。选择其中一种方式。.then() - 不要假设隐式全局变量仍可正常工作。3.x版本中所有顶级标识符必须是、
const或通过let导出。export - 不要自行发明异步替代方法。在方法和发布内容中仍为同步;不存在
Meteor.userId()。Meteor.userIdAsync() - 当方法或发布内容处理器需要读取框架绑定的时,不要使用箭头函数。箭头函数会忽略Meteor提供的调用上下文。
this - 不要仅因为应用迁移到Meteor 3就重写或
api.addFiles。它们在Atmosphere包中仍受支持。api.export
See also
另请参阅
- Async: ,
async-rewrites.md,call-vs-callAsync.md,async-cheatsheet.md,js-iterators.md.removed-functions.md - Runtime: ,
module-system.md,client-reactivity.md,publications.md,webapp-express.md.other-breaking-changes.md - Project: ,
package-triage.md,typescript-migration.md,react-migration.md.eval-cases.md - Current Meteor React integration after the upgrade: .
meteor-react
- 异步相关:、
async-rewrites.md、call-vs-callAsync.md、async-cheatsheet.md、js-iterators.md。removed-functions.md - 运行时相关:、
module-system.md、client-reactivity.md、publications.md、webapp-express.md。other-breaking-changes.md - 项目相关:、
package-triage.md、typescript-migration.md、react-migration.md。eval-cases.md - 升级后的当前Meteor React集成:。
meteor-react
Further reading (optional)
进一步阅读(可选)
Real-world migration write-ups for context, not for fixing specific
issues. The symptom router above is sufficient on its own. Open
only when the user asks for
narrative case studies or wants to calibrate effort and timeline.
references/community-case-studies.md提供真实世界的迁移案例分析,用于了解背景,而非修复特定问题。上述症状路由表已足以解决问题。仅当用户询问叙事性案例研究或希望评估工作量和时间线时,才查看。
references/community-case-studies.md