Skip to content

Commit a077571

Browse files
committed
Improve Turbopack compatibility, update docs on Turbopack
1 parent 057a928 commit a077571

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

packages/react-pdf/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Add React-PDF to your project by executing `npm install react-pdf` or `yarn add
7474

7575
#### Next.js
7676

77-
If you use Next.js, you may need to add the following to your `next.config.js`:
77+
If you use Next.js without Turbopack enabled, add the following to your `next.config.js`:
7878

7979
```diff
8080
module.exports = {
@@ -86,6 +86,26 @@ module.exports = {
8686
}
8787
```
8888

89+
If you use Next.js with Turbopack enabled, add `empty-module.ts` file:
90+
91+
```ts
92+
export default {};
93+
```
94+
95+
and add the following to your `next.config.js`:
96+
97+
```diff
98+
module.exports = {
99+
+ experimental: {
100+
+ turbo: {
101+
+ resolveAlias: {
102+
+ canvas: './empty-module.ts',
103+
+ },
104+
+ },
105+
+ },
106+
};
107+
```
108+
89109
### Configure PDF.js worker
90110

91111
For React-PDF to work, PDF.js worker needs to be provided. You have several options.

sample/next-app/empty-module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

sample/next-app/next.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
3+
experimental: {
4+
turbo: {
5+
resolveAlias: {
6+
// Turbopack does not support standard ESM import paths yet
7+
'./Sample.js': './app/Sample.tsx',
8+
/**
9+
* Critical: prevents " ⨯ ./node_modules/canvas/build/Release/canvas.node
10+
* Module parse failed: Unexpected character '�' (1:0)" error
11+
*/
12+
canvas: './empty-module.ts',
13+
},
14+
},
15+
},
316
webpack: (config) => {
417
/**
518
* Critical: prevents " ⨯ ./node_modules/canvas/build/Release/canvas.node

sample/next-pages/empty-module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

sample/next-pages/next.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
3+
experimental: {
4+
turbo: {
5+
resolveAlias: {
6+
// Turbopack does not support standard ESM import paths yet
7+
'./Sample.js': './pages/Sample.tsx',
8+
/**
9+
* Critical: prevents " ⨯ ./node_modules/canvas/build/Release/canvas.node
10+
* Module parse failed: Unexpected character '�' (1:0)" error
11+
*/
12+
canvas: './empty-module.ts',
13+
},
14+
},
15+
},
316
webpack: (config) => {
417
/**
518
* Critical: prevents " ⨯ ./node_modules/canvas/build/Release/canvas.node

0 commit comments

Comments
 (0)