使用 TypeScript
pnpm 在大多数情况下应该可以很好地与 TypeScript 配合使用。
🌐 pnpm should work well with TypeScript out of the box most of the time.
不保留符号链接
🌐 Do not preserve symlinks
你不应该在 preserveSymlinks 设置为 true 的情况下使用 TypeScript。TypeScript 无法在链接的 node_modules 中正确解析类型依赖。如果你因为某些原因确实需要保留符号链接,那么你应该将 pnpm 的 nodeLinker 设置为 hoisted。
🌐 You should not use TypeScript with preserveSymlinks set to true. TypeScript will not be able to resolve the type dependencies correctly in the linked node_modules. If you do need to preserve symlinks for some reason, then you should set pnpm's nodeLinker setting to hoisted.
工作区使用情况
🌐 Workspace usage
如果你的工作区中有不同版本的 @types/ 依赖,有时你可能会遇到问题。当一个包需要这些类型但在依赖中没有类型依赖时,就会发生这些问题。例如,如果你的依赖中有 antd,而 antd 依赖于 @types/react,如果工作区中有多个版本的 @types/react,你可能会遇到编译错误。实际上,这是 antd 端的问题,因为它本应将 @types/react 添加到 peerDependencies。幸运的是,你可以通过用缺失的同级依赖扩展 antd 来解决这个问题。你可以通过将其添加到你的 pnpm-workspace.yaml 来实现:
🌐 You might sometimes have issues if you have different versions of a @types/ dependency in a workspace. These issues happen when a package requires these types without having the type dependency in dependencies. For instance, if you have antd in your dependencies, which relies on @types/react, you might get a compilation error if there are multiple versions of @types/react in your workspace. This is actually an issue on antd's end because it should've added @types/react to peerDependencies. Luckily, you can fix this by extending antd with the missing peer dependency. You can do this either by adding this to your pnpm-workspace.yaml:
packageExtensions:
antd:
peerDependencies:
'@types/react': '*'
或者,你可以安装我们创建的一个配置依赖来处理这些问题 @pnpm/plugin-types-fixer。运行:
🌐 Alternatively, you can install a config dependency that we created to deal with these issues @pnpm/plugin-types-fixer. Run:
pnpm add @pnpm/plugin-types-fixer --config