React 组件库 - (插件 rpt2)RollupError:预期的“from”得到“typeof”

问题描述 投票:0回答:1

我正在使用 TypeScript 和 React 创建一个库,并且我希望该库包含 React 和 React Native 组件。当我在没有本机代码的情况下执行

npm run build
时,它编译得很好。但是,当我尝试添加本机组件然后运行
npm run build
时,我收到此错误:

(plugin rpt2) RollupError: Expected 'from', got 'typeof' in /Users/XXXXX/node_modules/react-native/index.js
12: 
13: // Components
14: import typeof AccessibilityInfo from './Libraries/Components/AccessibilityInfo/AccessibilityInfo';

我的堆栈是 React、TypeScript、rollup 和 babel。

这是我的 rollup.config.js:

import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from 'rollup-plugin-typescript2';
import postcss from 'rollup-plugin-postcss';
import del from 'rollup-plugin-delete';
import pkg from './package.json' assert { type: 'json' };

export default {
  input: 'src/index.ts',
  output: [
    {
      file: pkg.main,
      format: 'cjs',
      sourcemap: true,
    },
    {
      file: pkg.module,
      format: 'esm',
      sourcemap: true,
    },
  ],
  plugins: [
    del({ targets: 'dist/*' }),
    peerDepsExternal(),
    resolve(),
    commonjs(),
    typescript({
      tsconfig: 'tsconfig.build.json',
      useTsconfigDeclarationDir: true,
    }),
    postcss(),
  ],
};

我的所有组件都只是我在入口点index.ts中导出的

tsx
文件:

export { default as Footer } from './components/Footer';
export { default as Header } from './components/Header';

不确定我做错了什么。谢谢

reactjs typescript react-native build rollupjs
1个回答
0
投票

我也遇到这个问题了,请问你是怎么解决的?

© www.soinside.com 2019 - 2024. All rights reserved.