diegomura / diegomura/react-pdf

Assets cannot resolve when using Node API in NextJS API route

Open
#2,299 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
16.8k
Forks
1.3k
Avg merge
5h 6m
Merged PRs (30d)
52

Description

**Describe the bug**
I cannot use the Node rendering API on NextJS, as everytime I try to register a Font or use an Image, the path to the asset fails to be found or is resolved incorrectly internally on the library.

**To Reproduce**
Steps to reproduce the behavior including code snippet (if applies):
1. Create an API route in NextJS
2. Render a file using the `renderToFile` function in the API route. The file should contain some local fonts to be registered or images to be displayed.
3. See error - the assets and font paths resolve incorrectly. I have tried using Node's `process.cwd()` to set the asset paths to the absolute path within the project.

**Expected behavior**
The assets and font paths resolve incorrectly. I have tried using Node's `process.cwd()` to set the asset paths to the absolute path within the project, however the `not_found` error thrown, logs the incorrect absolute path - it is as if the given absolute path changes when the document is being rendered using the Node API.

**Desktop:**
- OS: [ Windows]
- Browser : [Chrome]
- React-pdf version [v3.1.9]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.