You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error: Cannot find package '/Users/ivanliang/Documents/project/marketplace/marketplace-web-next/node_modules/.pnpm/react-pdf-highlighter@8.0.0-rc.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-pdf-highlighter/dist/node_modules/pdfjs-dist/index.js' imported from /Users/ivanliang/Documents/project/marketplace/marketplace-web-next/node_modules/.pnpm/react-pdf-highlighter@8.0.0-rc.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-pdf-highlighter/dist/src/components/PdfLoader.js
Did you mean to import "pdfjs-dist/build/pdf.mjs"?
My env: node 20.18.0 nextjs 15.0.3 react: 18.3.1
Is this something related to the environment?
The text was updated successfully, but these errors were encountered:
@to-ivanliang I've found a solution for this in my build. It was my "vite.config.ts" file, I needed to add the react-pdf-highlighter to the ssr paramter.
import { reactRouter } from "@react-router/dev/vite";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
import path from "path";
import { reactRouterDevTools } from "react-router-devtools";
export default defineConfig(({ isSsrBuild }) => ({
build: {
rollupOptions: isSsrBuild
? {
input: "./server/app.ts",
}
: undefined,
},
plugins: [reactRouter(), tsconfigPaths()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./app"),
},
},
/*
* Use noExternal to bundle dependencies like 'react-pdf-highlighter' during SSR builds.
* This ensures compatibility by handling:
* - Browser-specific code for Node.js environments
* - CSS imports and assets through Vite's build process.
* - Non-CommonJS modules for SSR compatibility.
* Without this, issues like missing CSS imports, browser API errors, and module compatibility problems can occur.
*/
ssr: {
noExternal: ["react-pdf-highlighter"],
},
define: {
"process.env": {},
global: {},
},
}));
Uh oh!
There was an error while loading. Please reload this page.
After install with
pnpm install react-pdf-highlighter
,And tried with your example code
Got the error:
My env: node 20.18.0 nextjs 15.0.3 react: 18.3.1
Is this something related to the environment?
The text was updated successfully, but these errors were encountered: