To recreate
Create React TS app with Vite
npm init vite@latest vite-project --template react
Create sample pdf document
import React from 'react';
import pdf from '@react-pdf/renderer';
const { Page, Text, View, Document, StyleSheet } = pdf;
// Create styles
const styles = StyleSheet.create({
page: {
flexDirection: 'row',
backgroundColor: '#E4E4E4',
},
section: {
margin: 10,
padding: 10,
flexGrow: 1,
},
});
// Create Document Component
export const MyDocument = () => (
<Document>
<Page size='A4' style={styles.page}>
<View style={styles.section}>
<Text>Section #1</Text>
</View>
<View style={styles.section}>
<Text>Section #2</Text>
</View>
</Page>
</Document>
);
Delete the contents of App.ts. And add the following code from @react-pdf/renderer's example
import React from 'react';
import ReactDOM from 'react-dom';
import { PDFViewer } from '@react-pdf/renderer';
const App = () => (
<PDFViewer>
<MyDocument />
</PDFViewer>
);
Run the development server and check console for errors.
I tried to do it with create react app and everything worked fine. With Vite is that the error happens.