typescript 解决共享模块React的回退时出现汇总库错误

jrcvhitl  于 2023-01-10  发布在  TypeScript
关注(0)|答案(1)|浏览(128)

我正在使用Rollup和React 17.0.1创建一个设计系统库,不幸的是,我在使用该库时遇到此错误

Error: Can't resolve 'react/jsx-runtime'

汇总文件如下所示

export default [
    {
        input: "src/index.ts",
        output: [
            {
                file: packageJson.main,
                format: "cjs",
                exports: "auto",
                sourcemap: false,
                preserveModules: false
            },
            {
                file: packageJson.module,
                format: 'esm',
                sourcemap: false
            }
        ],
        plugins: [
            svgr(),
            json(),
            url(),
            peerDepsExternal(),
            resolve({
                jsnext: true,
                main: true,
                browser: true
            }),
            babel({
                babelrc: true,
                exclude: 'node_modules/**',
                presets: [
                    ["@babel/preset-react", { runtime: "automatic" }],
                ]
            }),
            commonjs({
                include: "node_modules/**",
                namedExports: {
                    'styled-components': [ 'styled', 'css', 'ThemeProvider' ],
                     "react/jsx-runtime": ["jsx", "jsxs", "Fragment"],
                     "react/jsx-dev-runtime": ["jsxDEV", "Fragment"]
                }
            }),
            typescript({ useTsconfigDeclarationDir: true }),
            postcss(),
            progress(),
            visualizer({})
        ],
        external: [...Object.keys(packageJson.peerDependencies || {})]
    },
    {
        input: 'types/index.d.ts',
        output: [{ file: 'dist/index.d.ts', format: "esm" }],
        external: [/\.css$/],
        plugins: [dts()],
    },
]

我寻找了很多解决方案,但我找不到任何一个好的...你可以帮助我吗?谢谢洛伦佐

z0qdvdin

z0qdvdin1#

它可能会有帮助。“@rollup/plugin-node-resolve”插件。

resolve({ extensions: [".js", ".jsx"] })

(tsx如果你正在使用 typescript ,请告诉我是否有帮助:)

相关问题