You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some NodeJS builtins (e.g. punycode) are deprecated, and replacement packages with the same name exist in NPM. It is desirable to have preferBuiltins set to false for these specific cases, while keeping it true for all other builtins (e.g. string_decoder is also available as both a builtin and a package, but in this case the builtin is stable and should be preferred).
Feature Proposal
Allow preferBuiltins to accept a regex, array, or function, matching the behaviour of e.g. external. The relevant code is already considering these on an import-by-import basis, so it should be possible without any restructuring needed.
For example, the config for the punycode example above could be:
(perhaps an even better API would be to reverse the config, preferring builtins by default and offering a preferModules config, since that would allow preferModules: ['punycode'], but that is not backwards-compatible, or at least introduces ambiguity if both options are used)
The text was updated successfully, but these errors were encountered:
In cases where the deprecated module is the only one that exists as both a builtin and a module, it is currently possible to use preferBuiltins: false, but this also requires listing all standard builtins explicitly as external:
import{builtinModules}from'module';constmodules=newSet(builtinModules);modules.delete('punycode');// we have to remove the entry that we WANT to be replacedexportdefault{plugins: [nodeResolve({preferBuiltins: false})],external: [/^node:/, ...modules],// prevent warnings during build};
This is not required when using preferBuiltins: true:
exportdefault{plugins: [nodeResolve({preferBuiltins: true})],external: [],// no need to explicitly list builtin modules};
So even in this case, having finer control over preferBuiltins would be beneficial.
Feature Use Case
Some NodeJS builtins (e.g.
punycode
) are deprecated, and replacement packages with the same name exist in NPM. It is desirable to havepreferBuiltins
set to false for these specific cases, while keeping ittrue
for all other builtins (e.g.string_decoder
is also available as both a builtin and a package, but in this case the builtin is stable and should be preferred).Feature Proposal
Allow
preferBuiltins
to accept a regex, array, or function, matching the behaviour of e.g.external
. The relevant code is already considering these on an import-by-import basis, so it should be possible without any restructuring needed.For example, the config for the
punycode
example above could be:(perhaps an even better API would be to reverse the config, preferring builtins by default and offering a
preferModules
config, since that would allowpreferModules: ['punycode']
, but that is not backwards-compatible, or at least introduces ambiguity if both options are used)The text was updated successfully, but these errors were encountered: