在使用rollup打包typescript时,使用pnpm作为包管理器时rollup.config.ts导出配置报错:
参考资料
- github issue: https://github.com/microsoft/TypeScript/issues/42873
- preserveSymlinks配置项说明: https://www.typescriptlang.org/tsconfig#preserveSymlinks
从报错信息的字面意思理解貌似是因为导出的配置和使用的库使用符号链接的时候对类型进行了推断,然而有没有对应的类型注释
sh
TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/rollup@2.74.1/node_modules/rollup'. This is likely not portable. A type annotation is necessary.
解决方法
增加tsconfig.json配置
json
{
"compilerOptions": {
"preserveSymlinks": true
}
}