Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: generate is not defined #468

Open
wonjongjang opened this issue Apr 4, 2024 · 2 comments
Open

ReferenceError: generate is not defined #468

wonjongjang opened this issue Apr 4, 2024 · 2 comments

Comments

@wonjongjang
Copy link

wonjongjang commented Apr 4, 2024

Describe the bug

If you run that code in React, an error will occur. Why?

To Reproduce

import type { Template } from '@pdfme/common';
import { BLANK_PDF } from '@pdfme/common';
import { generate } from '@pdfme/generator';

const template: Template = {
            basePdf: BLANK_PDF,
            schemas: [
                {
                    a: {
                        type: 'text',
                        position: { x: 0, y: 0 },
                        width: 10,
                        height: 10,
                    },
                    b: {
                        type: 'text',
                        position: { x: 10, y: 10 },
                        width: 10,
                        height: 10,
                    },
                    c: {
                        type: 'text',
                        position: { x: 20, y: 20 },
                        width: 10,
                        height: 10,
                    },
                },
            ],
        };

        const inputs = [{ a: 'a1', b: 'b1', c: 'c1' }];

     
        generate({ template, inputs }).then((pdf: Uint8Array) => {
            console.log('!', pdf);

            // Browser
            // const blob = new Blob([pdf.buffer], { type: 'application/pdf' });
            // window.open(URL.createObjectURL(blob));

            // Node.js
            // fs.writeFileSync(path.join(__dirname, `test.pdf`), pdf);
        });

Expected behavior

Your Environment

- @pdfme/common: "^3.4.3"
- @pdfme/generator: "^3.4.3"
- @pdfme/ui: "^3.4.3"

Your Error Log

ReferenceError: generate is not defined

Additional context

@hand-dot
Copy link
Collaborator

hand-dot commented Apr 8, 2024

Hey @wonjongjang
Can you give me a reproducable repo?

@n-at-han-k
Copy link

n-at-han-k commented Apr 18, 2024

Mozilla defines a ReferenceError as:

The ReferenceError object represents an error when a variable that doesn't exist (or hasn't yet been initialized) in the current scope is referenced.

Seems to me that your error lies with import { generate } from '@pdfme/generator';
The function generate isn't referencing anything.

Seems strange as I would expect you to get an error during the import, but as hand-dot says, it's hard to reproduce without an error as the code above should work.

Seems to me the error is not within the PDFme code but within your project, causing generate to reference nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants