svg / svgo

⚙️ Node.js tool for optimizing SVG files
https://svgo.dev/
MIT License
21.03k stars 1.39k forks source link

`package.json`/ `dist/svgo.browser.js` are no longer exported #1998

Closed XhmikosR closed 6 months ago

XhmikosR commented 6 months ago

Using v3.3.1:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in C:\Users\xmr\Desktop\svgomg\node_modules\svgo\package.json

Adding this in the exports fixes the issue but this means that if people where requiring other things that the ones exported right now, they will be broken:

"./package.json": "./package.json"

There must be a way to export everything again so that it's not a breaking change.

XhmikosR commented 6 months ago

For example:

Could not resolve import "svgo/dist/svgo.browser.js" in C:\Users\xmr\Desktop\svgomg\src\js\svgo-worker\index.js using exports defined in C:\Users\xmr\Desktop\svgomg\node_modules\svgo\package.json.
[08:01:06] Finished 'bound js' after 301 ms
[08:01:06] Finished 'bound js' after 465 ms
Could not resolve import "svgo/dist/svgo.browser.js" in C:\Users\xmr\Desktop\svgomg\src\js\svgo-worker\index.js using exports defined in C:\Users\xmr\Desktop\svgomg\node_modules\svgo\package.json.
'svgo/dist/svgo.browser.js' is imported by src/js/svgo-worker/index.js, but could not be resolved – treating it as an external dependency
No name was provided for external module 'svgo/dist/svgo.browser.js' in output.globals – guessing 'svgo_browser_js'

I can change the imports but this means that the changes in v3.3.0 are indeed breaking. :/

XhmikosR commented 5 months ago

@SethFalco I just tried 4.0.0-rc here: https://github.com/jakearchibald/svgomg/commit/b2cdb05271229f1976e7509edff61ffb51ac60d3

And it seems it doesn't work:

C:\Users\xmr\Desktop\svgomg>npm i svgo@4.0.0-rc.0 -D
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies

added 982 packages, and audited 1032 packages in 33s

163 packages are looking for funding
  run `npm fund` for details

17 vulnerabilities (1 low, 5 moderate, 10 high, 1 critical)

To address issues that do not require attention, run:
  npm audit fix

To address all issues possible (including breaking changes), run:
  npm audit fix --force

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.

C:\Users\xmr\Desktop\svgomg>npm run dev

> svgomg@1.16.0 dev
> gulp dev

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in C:\Users\xmr\Desktop\svgomg\node_modules\svgo\package.json
    at exportsNotFound (node:internal/modules/esm/resolve:303:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:650:9)
    at resolveExports (node:internal/modules/cjs/loader:591:36)
    at Module._findPath (node:internal/modules/cjs/loader:668:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1130:27)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (C:\Users\xmr\Desktop\svgomg\gulpfile.js:5:35)
    at Module._compile (node:internal/modules/cjs/loader:1376:14) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Did I miss something or something else is broken?

Thanks!

SethFalco commented 5 months ago

We don't export out package.json!

SVGOMG only used it for the version I believe, so you can do, which is the reason I added it:

const { VERSION } = require('svgo');

PS: A while back I opened a PR to update SVGO there too, but closed it later. In case it's helpful to you, these were the changes I proposed:

XhmikosR commented 5 months ago

Damn it, I misread the migration notes :)

So, this works https://github.com/jakearchibald/svgomg/commit/2c5835c3e8ecd1fe7406010f6805bd7ebeb48a70

Sorry for the noise!

XhmikosR commented 5 months ago

I don't follow the repos I have push rights so unless I'm CC'ed I won't see any issue :)

I'm keeping the xmr-dev branch for now since I have other PRs pending, but I left them as is after reading the new plans.

SethFalco commented 5 months ago

Sorry for the noise!

Don't be afraid to spam me if anything else comes up! And thanks for trying the RC and querying/reporting problems. Feedback on the release notes is also welcome if you think the issue was the wording.

XhmikosR commented 5 months ago

One thing I notice is the lack of extension in the browser export. Not a huge deal, but I prefer always adding an extension (plus xo errors by default for such cases).

Your call though :)

SethFalco commented 5 months ago

(plus xo errors by default for such cases)

Sorry, could you clarify what this means?