React-pdf not working with node (SyntaxError: Unexpected token '<')

128 Views Asked by At

I am creating a package that takes a react component and converts this component to a pdf.

I am using React-pdf to achieve this.

I followed their node API instruciton and when I run my code this error occurs

enter image description here

my code

index.js


  const template = await import(templatePath);
  ReactPDF.renderToFile(template, `${__dirname}/example.pdf`);

template.js


import { styles } from "./styles";
import { Page, Text, View, Document } from "@react-pdf/renderer";

const PDF = () => {
    return (
        <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>
    );
};

export default PDF;

How can I fix this issue?

0

There are 0 best solutions below