【发布时间】:2022-09-23 04:41:17
【问题描述】:
我需要构建可跨应用程序使用的可共享 React 组件。
为此,我正在/正在关注以下文章
我的配置看起来完全一样,除了 npm 包版本(甚至尝试使用相同的版本)
文件夹结构如下所示
rollup.config.js
import resolve from \"@rollup/plugin-node-resolve\";
import commonjs from \"@rollup/plugin-commonjs\";
import typescript from \"@rollup/plugin-typescript\";
import dts from \"rollup-plugin-dts\";
const packageJson = require(\"./package.json\");
export default [
{
input: \"src/index.ts\",
output: [
{
file: packageJson.main,
format: \"cjs\",
sourcemap: true,
},
{
file: packageJson.module,
format: \"esm\",
sourcemap: true,
},
],
plugins: [resolve(), commonjs(), typescript({ tsconfig: \"./tsconfig.json\" })],
},
{
input: \"dist/esm/types/index.d.ts\",
output: [{ file: \"dist/index.d.ts\", format: \"esm\" }],
plugins: [dts()],
},
];
npm 脚本
\"rollup\": \"rollup -c\"
但是,当我运行 npm run rollup 时,会引发以下错误
[!] 错误:无法解析入口模块 (dist/esm/types/index.d.ts)。
错误:无法解析入口模块(dist/esm/types/index.d.ts)请建议。谢谢!
-
在 rollup.config.js 中更改
dist/esm/types/index.d.ts->dist/esm/index.d.ts -
@Eliot 是的,您的建议解决了这个问题。非常感谢你。 :)
-
@Eliot您的建议有效。非常感谢