-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
upstreamCaused by upstream dependency. Could contribute, document error & workaround, or write Yarn patch.Caused by upstream dependency. Could contribute, document error & workaround, or write Yarn patch.
Description
I'm mainly just posting this issue for visibility and not expecting a fix since I think this is an issue with css-tree library not svgo.
Describe the bug
When using with nextjs app router and deploying to vercel, get:
⨯ Error: Cannot find module '../data/patch.json'
Require stack:
- /vercel/path0/node_modules/css-tree/lib/data-patch.js
at <unknown> (../../opt/rust/nodejs.js:2:12456)
at Function.Hr (../../opt/rust/nodejs.js:2:12834)
at Ae.e.<computed>.Me._load (../../opt/rust/nodejs.js:2:12426) {
code: 'MODULE_NOT_FOUND',
requireStack: [Array],
page: '/'
}
To Reproduce
import { optimize } from 'svgo'
// call optimize() anywhere during server side renderingVersions
- SVGO Version 4.0.0
- Node.js Version 22.x (on Vercel)
Explanation
css-treeuses a dynamicrequire('../data/patch.json')at runtime- The vercel bundler doesn't recognize
patch.jsonas a dependency and therefore excludes it from the bundled output (probably due to esm/commonjs incompatability)
Solution
Add to next.config.mjs:
serverExternalPackages: ['svgo'],
This will add ~1MB to your final server function build size, but it's the only solution I've found so far that works.
Metadata
Metadata
Assignees
Labels
upstreamCaused by upstream dependency. Could contribute, document error & workaround, or write Yarn patch.Caused by upstream dependency. Could contribute, document error & workaround, or write Yarn patch.