svgo icon indicating copy to clipboard operation
svgo copied to clipboard

Cannot find module '../data/patch.json'

Open whatworksglobal opened this issue 5 months ago • 6 comments

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-tree uses a dynamic require('../data/patch.json') at runtime
  • The vercel bundler doesn't recognize patch.json as 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.

whatworksglobal avatar Jul 02 '25 02:07 whatworksglobal

SVGO has nothing to do neither with Node.js nor CSS-tree. I think you should report to corresponding places.

GreLI avatar Jul 03 '25 10:07 GreLI

@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.

whatworksglobal avatar Jul 04 '25 10:07 whatworksglobal

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.

SethFalco avatar Jul 04 '25 14:07 SethFalco

Gives the same error with payload cms and next.js standalone build.

madfcat avatar Nov 30 '25 15:11 madfcat

just to point out - as the problem is with css-tree:

svgo is referencing 2 different versions v2 and v3 because of [email protected]

Image Image

PS. Also last update on css-tree was 12 months ago.... dont think this will really get fixed any time soon...

simonmaass avatar Dec 09 '25 14:12 simonmaass

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 😄

Kuuzoo avatar Dec 09 '25 14:12 Kuuzoo

Same here 😶

TimGuendel avatar Dec 15 '25 14:12 TimGuendel