Skip to content

Error with Vite on build #247

@Drilio

Description

@Drilio

Hello,
I try to use hCaptcha into my react app but I've got an error with Vite.
I use TypeScript and I think this is the hcaptcha/types package that cause the error.

import HCaptcha from "@hcaptcha/react-hcaptcha";

const myComponent = ()=> {
  const [token, setToken] = useState<any>(null);
  const captchaRef = useRef(null);

  const onLoad = () => {
    // this reaches out to the hCaptcha JS API and runs the
    // execute function on it. you can use other functions as
    // documented here:
    // https://docs.hcaptcha.com/configuration#jsapi
    hcaptcha.execute();
  };


  useEffect(() => {

    if (token)
      console.log(`hCaptcha Token: ${token}`);

  }, [token]);

return(
        <form>
          <HCaptcha
            sitekey="your-sitekey"
            onLoad={onLoad}
            onVerify={setToken}
            ref={captchaRef}
          />
        </form>
)
}

the error at built is the following :

------                                                                                                                                                                                                                                
 > [frontend 8/8] RUN npm run build:                                                                                                                                                                                                  
0.371                                                                                                                                                                                                                                 
0.371 > [email protected] build                                                                                                                                                                                                     
0.371 > tsc && vite build                                                                                                                                                                                                             
0.371 
7.872 vite v5.3.5 building for production...
7.953 transforming...
10.46 ✓ 806 modules transformed.
10.47 x Build failed in 2.56s
10.47 error during build:
10.47 [commonjs--resolver] Failed to resolve entry for package "@hcaptcha/types". The package may have incorrect main/module/exports specified in its package.json.
10.47     at packageEntryFailure (file:///app/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:46351:15)
10.47     at resolvePackageEntry (file:///app/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:46348:3)
10.47     at tryNodeResolve (file:///app/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:46164:16)
10.47     at Object.resolveId (file:///app/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:45914:19)
10.47     at file:///app/node_modules/rollup/dist/es/shared/node-entry.js:19774:40
10.47     at async PluginDriver.hookFirstAndGetPlugin (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:19674:28)
10.47     at async resolveId (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:18355:26)
10.47     at async ModuleLoader.resolveId (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:18758:15)
10.47     at async Object.resolveId (file:///app/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:12802:10)
10.47     at async PluginDriver.hookFirstAndGetPlugin (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:19674:28)
------
failed to solve: process "/bin/sh -c npm run build" did not complete successfully: exit code: 1

Is this a known issue and I missed something ?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions