Skip to content

Commit

Permalink
Improve Turbopack compatibility, update docs on Turbopack
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed May 14, 2024
1 parent 057a928 commit 79276df
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
24 changes: 22 additions & 2 deletions packages/react-pdf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Add React-PDF to your project by executing `npm install react-pdf` or `yarn add

#### Next.js

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

```diff
module.exports = {
Expand All @@ -86,6 +86,26 @@ module.exports = {
}
```

If you use Next.js with Turbopack enabled, add `empty-module.ts` file:

```ts
export default {};
```

and add the following to your `next.config.js`:

````diff

module.exports = {
+ experimental: {
+ turbo: {
+ resolveAlias: {
+ canvas: './empty-module.ts',
+ },
+ },
+ },
};

### Configure PDF.js worker

For React-PDF to work, PDF.js worker needs to be provided. You have several options.
Expand All @@ -101,7 +121,7 @@ pdfjs.GlobalWorkerOptions.workerSrc = new URL(
'pdfjs-dist/build/pdf.worker.min.js',
import.meta.url,
).toString();
```
````

> **Note**
> In Next.js:
Expand Down
1 change: 1 addition & 0 deletions sample/next-app/empty-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
13 changes: 13 additions & 0 deletions sample/next-app/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
turbo: {
resolveAlias: {
// Turbopack does not support standard ESM import paths yet
'./Sample.js': './app/Sample.tsx',
/**
* Critical: prevents " ⨯ ./node_modules/canvas/build/Release/canvas.node
* Module parse failed: Unexpected character '�' (1:0)" error
*/
canvas: './empty-module.ts',
},
},
},
webpack: (config) => {
/**
* Critical: prevents " ⨯ ./node_modules/canvas/build/Release/canvas.node
Expand Down
1 change: 1 addition & 0 deletions sample/next-pages/empty-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
13 changes: 13 additions & 0 deletions sample/next-pages/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
turbo: {
resolveAlias: {
// Turbopack does not support standard ESM import paths yet
'./Sample.js': './pages/Sample.tsx',
/**
* Critical: prevents " ⨯ ./node_modules/canvas/build/Release/canvas.node
* Module parse failed: Unexpected character '�' (1:0)" error
*/
canvas: './empty-module.ts',
},
},
},
webpack: (config) => {
/**
* Critical: prevents " ⨯ ./node_modules/canvas/build/Release/canvas.node
Expand Down

0 comments on commit 79276df

Please sign in to comment.