kkomelin / isomorphic-dompurify

Use DOMPurify on server and client in the same way
MIT License
415 stars 13 forks source link

Getting error "Package jsdom can't be external" after upgrading to Next.js 15 #295

Closed birdzai closed 3 weeks ago

birdzai commented 3 weeks ago

I thought I would test out upgrading a project to the newly release Next.js V15 and when running the app I'm getting this error in the server logs:

⚠ ./node_modules/.pnpm/isomorphic-dompurify@2.16.0/node_modules/isomorphic-dompurify
Package jsdom can't be external
The request jsdom matches serverExternalPackages (or the default list).
The request could not be resolved by Node.js from the project directory.
Packages that should be external need to be installed in the project directory, so they can be resolved from the output files.
Try to install it into the project directory by running npm install jsdom from the project directory.

I of course followed the suggestion of manually installing jsdom into my node_modules folder, but I hadn't needed to do this before.

kkomelin commented 3 weeks ago

Hey @birdzai , Thanks for reporting. Did you try what's recommended in the message?

Packages that should be external need to be installed in the project directory, so they can be resolved from the output files. Try to install it into the project directory by running npm install jsdom from the project directory.

birdzai commented 3 weeks ago

Yes, manually installing jsdom into node_modules fixed the error. I wasn't sure if you needed to be informed of having to perform this as something you cared about, so I thought I would raise it as an issue. Go ahead and close this issue if you think that's ok.

kkomelin commented 3 weeks ago

Thanks @birdzai. We hadn't change much in this project since Next.js 14, so it's likely it's related to the latest Next.js update. But adding jsdom to external dependencies is a way to do it currently, though I understand that it's not very convenient https://github.com/kkomelin/isomorphic-dompurify/issues/54#issuecomment-1458603825

kkomelin commented 3 weeks ago

Thanks again for reporting @birdzai !