resolvers: Uncaught ReferenceError: exports is not defined

trying to:

import { zodResolver } from "@hookform/resolvers/zod";

gives me:

Uncaught ReferenceError: exports is not defined
    at Module../node_modules/@hookform/resolvers/dist/zod.js (zod.js:11)
    at __webpack_require__ (bootstrap:789)
    at fn (bootstrap:100)
    at Object../node_modules/@hookform/resolvers/zod.js (zod.js:1)
    at __webpack_require__ (bootstrap:789)
    at fn (bootstrap:100)
    ...

This is a Rails webpacker + typescript app.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 52 (17 by maintainers)

Commits related to this issue

Most upvoted comments

@amankkg I’m glad it solves your problem ! 😃 But 1.4.0-beta.1 was a mistake with semantic-release. Please use 2.0.0-beta.3 instead.


Next.js’s users have the same problem since 1.3.1 : #100 Workaround possible: use the v1.3.0 or try the v2 beta

EDIT (2/1/2020): Same for Snowpack users


For everyone which want to try the v2, you can install the @hookform/resolvers@beta, at this time the beta.3 contains:

  • A TypeScript fix for Yup
  • A better modules support (without breaking changes)

Feedbacks are really appreciated 😃 If some of you get some errors with modules, please reply here.

👋🏻 You can try the last version v1.3.6. The issue should be solved

@asotog At the same time of react-hook-form v7

@bluebill1049 Do we have a “deadline” ?

No, we don’t. It’s open-source, we are all working on this in our free time. So no pressure, we get it right and we ship it out. I am planning to do a quick video to cover some of the major changes and improvements, then we can release a beta version and get more users to “test” this out.

I am getting this too for yup on a non-rails project. I am only getting the error on production build and not in development build.

Edit: after adding sourceType: 'unambiguous' into babel.config.js, I am able to resolve the runtime error. The issue might be https://github.com/webpack/webpack/issues/4039#issuecomment-419284940.

I was having this issue with yup and nextjs. After downgrading to 1.3.0, everything seems to be working OK. Thanks for the workaround @jorisre

using “@hookform/resolvers”: “2.0.0-beta.3” with “next”: “10.0.7” seems to work perfectly!

@hamzahasbi It works well for me, thanks.

@asotog At the same time of react-hook-form v7

@bluebill1049 Do we have a “deadline” ?

using “@hookform/resolvers”: “2.0.0-beta.3” with “next”: “10.0.7” seems to work perfectly! Thanks !

@borivojevic Happy to try Snowpack, esbuild is fast as expected 🚀

In your example you use the version 1.3.3 which have an issue with module exports (solved in v2). In your case, I recommend to use the 1.3.0 or try the v2 beta. I get your example working with these both versions.

I added a note for Snowpack users : https://github.com/react-hook-form/resolvers/issues/71#issuecomment-754623998

Hope it helps

@jorisre I hope this example helps.

yarn install && yarn start should result in error.

This is the implementation that’s problematic.

It seems to work for @tajdien, can you share a working example please ?

@borivojevic I’m not familiar with Snowpack but if you have a reproductible example to provide then I can investigate thanks !

Another workaround that works with snowpack v3.0.11 would be:

import hookforResolvers from '@hookform/resolvers/yup';
const yupResolver = hookforResolvers.yupResolver;

I had the same issue with 1.3.2 using snowpack. 2.0.0-beta.3 didn’t work either.

Although snowpack suggests this workaround that seems to be working for me:

// doesn't work
import { yupResolver } from '@hookform/resolvers/yup';

// it works
import type { yupResolver } from '@hookform/resolvers/yup';

I’m facing the same issue as https://github.com/react-hook-form/resolvers/issues/100 ,

andres@andres:~/Entrepreneurship/TeVi$ yarn build

yarn run v1.22.10
$ next build
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
info  - Using external babel configuration from /home/andres/Entrepreneurship/TeVi/.babelrc
info  - Creating an optimized production build  
info  - Compiled successfully

> Build error occurred
/home/andres/Entrepreneurship/TeVi/node_modules/@hookform/resolvers/dist/yup.js:2
import { transformToNestObject } from 'react-hook-form';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/home/andres/Entrepreneurship/TeVi/node_modules/@hookform/resolvers/yup.js:1:18)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) {
  type: 'SyntaxError'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Now, I can’t deploy to vercel 😦

The versions I’m using are:

    "@hookform/resolvers": "^1.2.0",
    "next": "^10.0.4",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-hook-form": "^6.13.1",
    "yup": "^0.32.8"

I had this lightbulb moment too 😃 But unfortunately that solution alone didn’t help. Thanks anyway John.

Having the same issue, also using rails/webpacker. Downgrading to 0.1.1 did resolve.

^1.3.0 will install the latest version >=1.3.0 <2.0.0. If you want to pin a specific version you should remove the caret ^.

using “@hookform/resolvers”: “2.0.0-beta.3” with “next”: “10.0.7” seems to work perfectly!

@hamzahasbi It works well for me, thanks.

For me too !! 😄

Thanks @jorisre. I can confirm that v2 beta works on this smaller example as well.

@MontoyaAndres try to use the latest beta version.

I had the same issue with 1.3.2 using snowpack. Upgrading it to 2.0.0-beta.3 resolved the issue for me aswell.

@jorisre it is quite messy 😅 let me know if you need clear and stable reproduction repo

@jorisre hmm on 1.3.0 it works properly

here is my WIP https://github.com/amankkg/frontend-template

Hi all, the last version 1.3.1 should fix this issue, someone can confirm ? Thanks

Thanks for reporting, I’m looking for a solution

@batamire Hi 👋🏻

Does that error occur at build time ?

Can you provide more informations please ? Your code snippets doesn’t help me 😕