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

PDF generation not working on production #3

Open
lapoguidi opened this issue Jul 2, 2023 · 2 comments
Open

PDF generation not working on production #3

lapoguidi opened this issue Jul 2, 2023 · 2 comments

Comments

@lapoguidi
Copy link

Testing in production with adapter-node gettings

ReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and 'package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at requireFontkit (file:///home/ubuntu/build/server/chunks/_server-17432636.js:39657:45)
    at file:///home/ubuntu/build/server/chunks/_server-17432636.js:64668:22
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

The error occurs here: var trie = new UnicodeTrie(fs.readFileSync(__dirname + '/data.trie'));
If this occurred also for you, how have you solved this?

Thanks

Lapo

@phartenfeller
Copy link
Owner

Ok, weird; it works for me. How are you running the production build, and what is your node version?

From the error message, it seems like there is some ESM <-> CommonJS mismatch. I used __dirname nowhere, so it has to be in some dependency.

@lapoguidi
Copy link
Author

lapoguidi commented Jul 3, 2023

Hello, thanks for reply.
I tried with 18 LTS: v18.6.0 then I upgraded to v18.6.2.

The error occurs when pdfmake is imported.

Anyway __dirname is used in a pdfKit dependency: https://github.com/foliojs-fork/fontkit

var trie = new UnicodeTrie(fs.readFileSync(__dirname + '/data.trie'));

I'm looking for a workaround : )

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

No branches or pull requests

2 participants