- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 23
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 uses deprecated subpath folder mappings in exports #17
Comments
Yes, I plan to publish updated package Some things I'll look further into in the morning:
|
Apparently earlier versions of Node will happily ignore subpath patterns: https://github.com/nodejs/node/blob/v12.8.1/doc/api/esm.md#resolution-algorithm, so As for the difference between Lastly, the |
A few things to note… At first it might seem like a nice idea to configure the package // "./public/": "./public/" (deprecated, as it is now)
import extractFiles from 'extract-files/public/extractFiles.js';
const extractFiles = require('extract-files/public/extractFiles.js');
const extractFiles = require('extract-files/public/extractFiles');
// "./*": "./public/*"
import extractFiles from 'extract-files/extractFiles.js';
const extractFiles = require('extract-files/extractFiles.js');
// "./*": "./public/*.js"
import extractFiles from 'extract-files/extractFiles';
const extractFiles = require('extract-files/extractFiles'); But, then legacy tools that don't understand the package
So, for better compatibility with the wider ecosystem it’s better to stick to: // "./public/*": "./public/*"
import extractFiles from 'extract-files/public/extractFiles.js';
const extractFiles = require('extract-files/public/extractFiles.js');
// "./public/*": "./public/*.js"
import extractFiles from 'extract-files/public/extractFiles';
const extractFiles = require('extract-files/public/extractFiles');
So, it seems the best option is: // "./public/*": "./public/*"
import extractFiles from 'extract-files/public/extractFiles.js';
const extractFiles = require('extract-files/public/extractFiles.js'); The sad thing about this is, unlike before, when using It would be cool if there is a way to continue supporting |
Node.js doesn't seem to document array syntax for package export fallbacks, but here is the webpack docs for it: https://webpack.js.org/guides/package-exports/#alternatives You would think that Node.js would be able to resolve this, but it can't:
// Real file path: ./public/foo.js
import foo from 'extract-files/public/foo';
import foo from 'extract-files/public/foo.js';
const foo = require('extract-files/public/foo');
const foo = require('extract-files/public/foo.js'); |
In https://nodejs.org/api/esm.html#esm_resolver_algorithm_specification, PACKAGE_TARGET_RESOLVE, arrays will fallback in case of invalid value or a conditional doesn't match, and in any case without looking up whether the resolved target exists; so an array of strings is useless and will always use the first array value. |
(node:31) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./public/" in the "exports" field module resolution of the package at /server/node_modules/extract-files/package.json. Not sure what exactly I can do about this. Received this warning in my project. |
@Dolosolow it's just a warning, so your project should still function for now. But it's definitely a good idea to update your dependencies so that you're using the latest |
yes it is a dependency of one of my dependencies. Thank you for replying. |
A change in node means package export paths need to be explicitly defined with patterns because folder exports are deprecated: https://nodejs.org/api/packages.html#packages_subpath_folder_mappings jaydenseric/extract-files#17
package.json
'sexports
uses subpath folder mappings (at https://github.com/jaydenseric/extract-files/blob/v9.0.0/package.json#L37), which is deprecated since Node v12.20.0 / v14.13.0, replaced with subpath patterns (which apparently exist since the beginning of exports maps too).See https://nodejs.org/api/packages.html#packages_subpath_folder_mappings
The main difference is that the required paths have to exactly match, whether you use
require()
orimport
to get to the subpath (whereas with subpath folder mappings, the file extension will be automatically added when usingrequire()
, but not when usingimport
).Fwiw, see rollup/plugins#684 (comment) for the details of the Node algorithm applied to the specific case of
require("extract-files/public/extractFiles")
.The text was updated successfully, but these errors were encountered: