-
-
Notifications
You must be signed in to change notification settings - Fork 916
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
package.json is not defined by "exports" #444
Comments
@evdama could you provide actual steps that let me reproduce your error (meaning, code that I can execute)? "grading from v7.0.3 to v8.0.0 and running npm build in a Svelte project" does not really help since I have no clue about the details of your project… |
I'm using uuid inside my import { v4 as uuidv4 } from 'uuid'
... more code...
const setNonceMiddleware = ( request, response, next ) => {
try {
response.locals.nonce = uuidv4()
next()
} catch ( error ) {
console.error ( 'error from setNonceMiddleware: ', error )
}
} I 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 |
OK, this is strange. Judging from the stack trace of your error this looks much more like an issue with https://github.com/sveltejs/rollup-plugin-svelte though… Apparently the svelte rollup plugin uses
which likely has problems with modern Node.js module loading since its latest version has been published 6 years ago: I don't think we could or should solve this in this library here. I think the right place to report this issue would be https://github.com/sveltejs/rollup-plugin-svelte/issues |
@ctavan thanks much, I'm trying to catch one of the svelte devs (@Conduitry) on discord, ask him what he thinks is best i.e. me filling an issue about an outdated |
@evdama I dug a little bit into it, I think it's a problem directly in the svelte rollup plugin, see sveltejs/rollup-plugin-svelte#104 |
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. |
@Danny-A can you specify what you mean by "exact same problem"? Do you get exactly the same stack trace? Do you use svelte and |
@TrySound I think you are more familiar with use cases of requiring |
@ctavan Sorry for the lack of context. I get a Warning in RN. I don't get a stack trace and I am not using rollup.
|
There is no any requirement for bundlers because they mostly do not support native node modules. Perhaps package.json should always be in exports list. See here |
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 `exports` field to package.json, only the paths defined in that field are accessible to Node.js. In order to support introspection of the package.json file itself it has to be listed as an export as well. See also: ai/nanoevents#44 (comment) Fixes #444
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 `exports` field to package.json, only the paths defined in that field are accessible to Node.js. In order to support introspection of the package.json file itself it has to be listed as an export as well. See also: ai/nanoevents#44 (comment) Fixes #444
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 `exports` field to package.json, only the paths defined in that field are accessible to Node.js. In order to support introspection of the package.json file itself it has to be listed as an export as well. See also: ai/nanoevents#44 (comment) Fixes #444
For the time being the warning can simply be ignored for I think it might make more sense to actually fix this in |
In general, I think it's a good idea for packages to explicitly add However, unless the ecosystem is consistently willing to do this, tooling will have to determine a different mechanism for accessing package.jsons - something like |
To rephrase @ljharb's suggestion (assuming Node.js won't change the current behavior, see nodejs/node#33460):
|
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 `exports` field to package.json, only the paths defined in that field are accessible to Node.js. In order to support introspection of the package.json file itself it has to be listed as an export as well. See also: ai/nanoevents#44 (comment) Fixes #444
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 `exports` field to package.json, only the paths defined in that field are accessible to Node.js. In order to support introspection of the package.json file itself it has to be listed as an export as well (see: ai/nanoevents#44 (comment)). It is currently being discussed to change Node.js' behavior again, see: nodejs/node#33460 Until then, adding package.json to the exports field should result in minimum breakage. Fixes #444
Just release |
Hi @ctavan , I am seeing the same error using the latest version Package subpath './v4' is not defined by "exports" in /Users/path-to-project/nested/in/node-modules-folder/node_modules/uuid/package.json
$ node -v
v14.4.0 |
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: uuidjs/uuid#444 Fixes #107
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: uuidjs/uuid#444 Fixes #107
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: ``` warn Package pretty-bytes has been ignored because it contains invalid configuration. Reason: Package subpath './package.json' is not defined by "exports" in /Users/****/Applications/****/****/app/node_modules/pretty-bytes/package.json ``` There was a similar Issue in `uuidjs`, for discussion you can see this issue uuidjs/uuid#444 (comment)
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: uuidjs/uuid#444 Fixes #107
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:
Expected behavior
A rollup bundle without an error as shown below.
Runtime
Additional context
This is the command line output after upgrading from v7.0.3 to v8.0.0 in a Svelte project
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
The text was updated successfully, but these errors were encountered: