Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails with "flatted" dependency: './package.json' is not defined by "exports" #193

Closed
delventhalz opened this issue Jan 26, 2022 · 4 comments

Comments

@delventhalz
Copy link

Hello!

Recently added a new ultity flatted to my project to handle some circular JSON. Unfortunately, this seems to have broken the build. I get the following error, and the build fails:

[!] (plugin svelte) Error: Package subpath './package.json' is not defined by "exports" in /Users/zac/Code/mfe-dashboard/node_modules/flatted/package.json
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in /Users/zac/Code/mfe-dashboard/node_modules/flatted/package.json
    at throwExportsNotFound (internal/modules/esm/resolve.js:299:9)
    at packageExportsResolve (internal/modules/esm/resolve.js:522:3)
    at resolveExports (internal/modules/cjs/loader.js:449:36)
    at Function.Module._findPath (internal/modules/cjs/loader.js:489:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:875:27)
    at Function.requireRelative.resolve (/Users/zac/Code/mfe-dashboard/node_modules/require-relative/index.js:30:17)
    at tryResolve (/Users/zac/Code/mfe-dashboard/node_modules/rollup-plugin-svelte/index.js:50:19)
    at Object.resolveId (/Users/zac/Code/mfe-dashboard/node_modules/rollup-plugin-svelte/index.js:177:21)
    at /Users/zac/Code/mfe-dashboard/node_modules/rollup/dist/shared/node-entry.js:13117:25

Found a discussion of a similar issue with uuid. Seems like flatted could fix this by adding "./package.json": "./package.json" to their package.json... but is there no way Svelte rollup can handle this more gracefully? Maybe throw a warning but find the package.json procedurally as a fallback? Flatted is a fairly well used utility (23 million downloads a week), and it seems strange Svelte simply would not support it over what appears to be a fairly small issue.

@Conduitry
Copy link
Member

If a library has exports in its package.json, that indicates to Node that those are the only things that can be imported or required from the package, and if it doesn't include package.json, we can't access whatever/package.json.

I'm not sure there's any reasonable for the Rollup plugin to do here to access this, other than to completely sidestep Node's module resolution and manually load this file and parse it, which doesn't sound ideal.

If a package decides to use pkg.exports, it really is kind of on them to expose package.json because there are a lot of valid reasons that other packages might want to be able to access that. I'd suggest an issue or PR with flatted to add that file to their exports map.

@benmccann
Copy link
Member

PR here: WebReflection/flatted#54

@delventhalz
Copy link
Author

delventhalz commented Jan 26, 2022

Hey, I appreciate the fast response and PR!

This all sounds reasonable. I agree that it seems like more of a flatted problem than a rollup problem, but I do wonder how many other major libraries out there fall into this trap? It may not be ideal to rely on each individual maintainer to merge updates before a library can be used with Svelte. Not saying the trade offs of some edge case workaround are necessarily worth it either, just that it may be worth thinking through.

lonvia added a commit to waymarkedtrails/waymarkedtrails-website that referenced this issue Jan 30, 2022
With node 14 there is a lot of trouble with packages with explicit
exports that do not include package.js. This includes at the moment:

- d3-*
- mapbox-style-def
- threads
- float16

The first two are held at their versions for the moment, the latter
two are manually removed from yarn.lock.

Issue at nodejs: nodejs/node#33460
Issue with rollup: sveltejs/rollup-plugin-svelte#193
@benmccann
Copy link
Member

We're going to change the behavior related to this. In the meantime, closing as a duplicate of #181

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants