uuid: package.json is not defined by "exports"
Describe the bug
‘./package.json’ is not defined by “exports” when upgrading from v7.0.3 to v8.0.0
To Reproduce
Steps to reproduce the behavior:
- upgrading from v7.0.3 to v8.0.0 and running npm build in a Svelte project
- See error
Expected behavior
A rollup bundle without an error as shown below.
Runtime
- OS: macOS
- Runtime: Node.js
- Runtime Version: 14.1.0
Additional context
This is the command line output after upgrading from v7.0.3 to v8.0.0 in a Svelte project
> Package subpath './package.json' is not defined by "exports" in /Users/sa/0/edm/node_modules/uuid/package.json
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in /Users/sa/0/edm/node_modules/uuid/package.json
at applyExports (internal/modules/cjs/loader.js:491:9)
at resolveExports (internal/modules/cjs/loader.js:507:23)
at Function.Module._findPath (internal/modules/cjs/loader.js:635:31)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1007:27)
at Function.requireRelative.resolve (/Users/sa/0/edm/node_modules/require-relative/index.js:30:17)
at tryResolve (/Users/sa/0/edm/node_modules/rollup-plugin-svelte/index.js:50:19)
at Object.resolveId (/Users/sa/0/edm/node_modules/rollup-plugin-svelte/index.js:177:21)
at /Users/sa/0/edm/node_modules/rollup/dist/shared/rollup.js:18217:25
I found some additional information in a SO post that might very well be related to the issue I’m seeing https://stackoverflow.com/questions/61621828/getting-strange-error-using-uuid-npm-module-what-am-i-doing-wrong/61730597#61730597
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 27 (13 by maintainers)
Commits related to this issue
- fix: export package.json required by react-native and bundlers It appears that react-native and some bundlers rely on being able to introspect the package.json file of a npm module. After adding the ... — committed to uuidjs/uuid by ctavan 4 years ago
- fix: export package.json required by react-native and bundlers It appears that react-native and some bundlers rely on being able to introspect the package.json file of a npm module. After adding the ... — committed to uuidjs/uuid by ctavan 4 years ago
- fix: export package.json required by react-native and bundlers It appears that react-native and some bundlers rely on being able to introspect the package.json file of a npm module. After adding the ... — committed to uuidjs/uuid by ctavan 4 years ago
- fix: export package.json required by react-native and bundlers It appears that react-native and some bundlers rely on being able to introspect the package.json file of a npm module. After adding the ... — committed to uuidjs/uuid by ctavan 4 years ago
- fix: export package.json required by react-native and bundlers (#449) It appears that react-native and some bundlers rely on being able to introspect the package.json file of a npm module. After add... — committed to uuidjs/uuid by ctavan 4 years ago
- Manually export package.json to support introspective tools Tools such as Components.js and react-native require introspection of the package.json file. Since the new export syntax does not imply pac... — committed to rubensworks/AsyncIterator by rubensworks 3 years ago
- Manually export package.json to support introspective tools Tools such as Components.js and react-native require introspection of the package.json file. Since the new export syntax does not imply pac... — committed to RubenVerborgh/AsyncIterator by rubensworks 3 years ago
- fix: export package.json Apparently, React Native and various bundler tools expect to be able to import/require package.json, which will fail if `exports` is being used but not exporting package.json... — committed to ianprime0509/pitchy by ianprime0509 2 years ago
- fix: export package.json (#108) Apparently, React Native and various bundler tools expect to be able to import/require package.json, which will fail if `exports` is being used but not exporting pac... — committed to ianprime0509/pitchy by ianprime0509 2 years ago
- fix(package.json): add package.json to exports If you are using bundlers like metro in rn-native (or tools that make use of metainformation of packages) you will recieve an import warning like: ``` ... — committed to tastydev/pretty-bytes by tastydev 2 years ago
- fix: export package.json (#108) Apparently, React Native and various bundler tools expect to be able to import/require package.json, which will fail if `exports` is being used but not exporting pac... — committed to xbucks/react-responsive by ianprime0509 2 years ago
I fixed it by running
npm ci.In general, I think it’s a good idea for packages to explicitly add
"./package.json": "./package.json"to their"exports"field.However, unless the ecosystem is consistently willing to do this, tooling will have to determine a different mechanism for accessing package.jsons - something like
findPackageJSONFrom(path.dirname(require.resolve('pkg'))).Hi @ctavan ,
I am seeing the same error using the latest version
8.1.0but for the v4 exports:Just release
uuid@8.1.0which now exportspackage.json, so the problem reported here should be gone for now.@alayor thanks , save my ass
It is not only a Svelte Rollup problem.
I upgraded to v8.0.0 in my React Native project and encountered the exact same problem.
To rephrase @ljharb’s suggestion (assuming Node.js won’t change the current behavior, see https://github.com/nodejs/node/issues/33460):
package.jsonmust export it.package.jsongracefully (i.e. without crashing).package.jsoncould warn if packages don’t exportpackage.jsonin order to help package maintainers decide if they need to export it or not.For the time being the warning can simply be ignored for
uuid, the functionality is not affected!I think it might make more sense to actually fix this in
react-nativeinstead of adding this workaround to every single module on npm. If you agree, feel free to give your 👍 for https://github.com/react-native-community/cli/issues/1168I’m using uuid inside my
server.jslike soI don’t use uuid anywhere else in my app, just the snippet above. I’ll also provide a gist of my rollup config that might help, it’s a Sapper (Svelte) project with a client and a server as well as a serviceworker section: https://gist.github.com/7b56754df52b5b26b1db3f2873cee726
Thanks for the pointers. The problem is actually with npm/lerna where one package didn’t get it’s (newer) version of uuid installed locally and was using a (probably) deduped one in the parent node_modules folder coming from an older package. Quite a specific use case, nothing wrong with uuid 👍
This is a different issue, support for deep imports has been deprecated in
7.0.0and removed in8.0.0: https://github.com/uuidjs/uuid#deep-requires-no-longer-supported