resolver.js 996 B

12345678910111213141516171819202122
  1. module.exports = (path, options) => {
  2. // Call the defaultResolver, so we leverage its cache, error handling, etc.
  3. return options.defaultResolver(path, {
  4. ...options,
  5. // Use packageFilter to process parsed `package.json` before
  6. // the resolution (see https://www.npmjs.com/package/resolve#resolveid-opts-cb)
  7. packageFilter: (pkg) => {
  8. // jest-environment-jsdom 28+ tries to use browser exports instead of default exports,
  9. // but @hookform/resolvers only offers an ESM browser export and not a CommonJS one. Jest does not yet
  10. // support ESM modules natively, so this causes a Jest error related to trying to parse
  11. // "export" syntax.
  12. //
  13. // This workaround prevents Jest from considering @hookform/resolvers module-based exports at all;
  14. // it falls back to CommonJS+node "main" property.
  15. if (pkg.name === '@hookform/resolvers') {
  16. delete pkg['exports'];
  17. delete pkg['module'];
  18. }
  19. return pkg;
  20. },
  21. });
  22. };