Cannot find module '../data/patch.json'
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 rendering
Versions
- 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.
SVGO has nothing to do neither with Node.js nor CSS-tree. I think you should report to corresponding places.
@GreLI SVGO does use css-tree? https://github.com/search?q=repo%3Asvg%2Fsvgo+csstree&type=code
This is the issue in csstree: https://github.com/csstree/csstree/issues/314
But yeah you can close this issue, just wanted to post a solution for people having the same problem.
No need to close it yet! I wanted to take time to look at this later to decide if I'll leave it to upstream, or if we'll include some documentation to account for this.
In any case, I think it'd valuable to keep the issue open so we know to keep track of upstream and update the dependency once it's resolved.
It's a real issue that affects us, even if it's caused upstream, so I'd like to continue keeping track of it. In other words, regardless of the cause, it's still an error that SVGO is shipping.
Gives the same error with payload cms and next.js standalone build.
just to point out - as the problem is with css-tree:
svgo is referencing 2 different versions v2 and v3 because of [email protected]
PS. Also last update on css-tree was 12 months ago.... dont think this will really get fixed any time soon...
No need to close it yet! I wanted to take time to look at this later to decide if I'll leave it to upstream, or if we'll include some documentation to account for this.
In any case, I think it'd valuable to keep the issue open so we know to keep track of upstream and update the dependency once it's resolved.
It's a real issue that affects us, even if it's caused upstream, so I'd like to continue keeping track of it. In other words, regardless of the cause, it's still an error that SVGO is shipping.
Hi there @SethFalco, is there any update on this thought?
As I'm personally having trouble using the newest version of @nuxt/image because of this issue, I'd love to get this sorted as soon as possible 😄
Same here 😶