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

Error : build: Module not found: Can’t resolve ‘../build/Release/canvas.node’ #1592

Closed
4 tasks done
mz-chansm opened this issue Aug 8, 2023 · 5 comments
Closed
4 tasks done
Labels
question Further information is requested

Comments

@mz-chansm
Copy link

mz-chansm commented Aug 8, 2023

Before you start - checklist

  • I followed instructions in documentation written for my React-PDF version
  • I have checked if this bug is not already reported
  • I have checked if an issue is not listed in Known issues
  • If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo

Description

  • next.js 13.4
  • turborepo
  • node 18.4

Two out of ten people had this error.
I merged it into the development and installed it, but there was an error.
The two are using m1 mac
The error name is as follows.
error :platform:build: Module not found: Can’t resolve ‘../build/Release/canvas.node’

As you told me, the setting is as follows.

next.config.js

module.exports = {
  reactStrictMode: true,
  transpilePackages: ['ui'],
  output: 'export',
  trailingSlash: true,
  webpack: (config) => {
    config.module.rules.push({
      test: /\.node/,
      use: {
        loader: 'raw-loader',
      },
    })

    return config
  },
}

package.json

  "dependencies": {
 "react-pdf": "^7.3.3",
},
  "devDependencies": {
    "raw-loader": "^4.0.2",
  }
}

pdf.tsx

'use client'
import { pdfjs, Document, Page } from 'react-pdf'
import 'react-pdf/dist/esm/Page/AnnotationLayer.css'
import 'react-pdf/dist/esm/Page/TextLayer.css'

import { File, OnPasswordCallback, PasswordResponse } from 'react-pdf/dist/cjs/shared/types'
import { useState } from 'react'

pdfjs.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker.min.js', import.meta.url).toString()

type OnPassword = (callback: OnPasswordCallback, reason: PasswordResponse) => void
const PdfViewer = () => {
.../
  const [file, setFile] = useState<File>('/sample2.pdf')
     return (
    <>
      <div id="pdfWrap">
        <Document file={file} onLoadSuccess={onDocumentLoadSuccess} onPassword={onPassword}>
          <Page renderTextLayer={false} pageNumber={pageNumber} />
        </Document>
      </div>
      <p>
        Page {pageNumber} of {numPages}
      </p>
    </>
  )
}

Steps to reproduce

  1. Import PdfViwer from another component
  2. when pnpm build => error

Expected behavior

N/A

Actual behavior

N/A

Additional information

No response

Environment

  • Browser (if applicable):
  • React-PDF version:
  • React version:
  • Webpack version (if applicable):
@mz-chansm mz-chansm added the bug Something isn't working label Aug 8, 2023
@mz-chansm mz-chansm changed the title platform:build: Module not found: Can’t resolve ‘../build/Release/canvas.node’ Error : build: Module not found: Can’t resolve ‘../build/Release/canvas.node’ Aug 8, 2023
@jtaox
Copy link

jtaox commented Aug 8, 2023

I have the same problem that's been solved here Automattic/node-canvas#1825 (comment)

@wojtekmaj wojtekmaj added question Further information is requested and removed bug Something isn't working labels Aug 8, 2023
@mz-chansm
Copy link
Author

I have the same problem that's been solved here Automattic/node-canvas#1825 (comment)

thank you
why reason?
only m1 mac issue ?

@jtaox
Copy link

jtaox commented Aug 9, 2023

I have the same problem that's been solved here Automattic/node-canvas#1825 (comment)

thank you why reason? only m1 mac issue ?

prebuilds node-canvas dependency is not compatible with ARM CPU.
I only encountered this issue on m1 mac.

@mortocks
Copy link

Does this mean there are potential deployment issues when using this library i.e. can you deploy to netlify vercel etc or do you need to create a more customised install environment?

@wojtekmaj
Copy link
Owner

I have just added functional Next.js samples in fc18d18. Builds just fine on my M2 Mac. Check if these are working for you as well.

In the meantime, I'm closing this; if samples aren't working in some configurations, we will look at them instead.

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

No branches or pull requests

4 participants