question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not working on nextjs

See original GitHub issue

The lib is throwing the following error when next build is ran ReferenceError: navigator is not defined at Object.getBrowser (C:\projects\web-ssd-cms-api-bakcend\web-ssd-website-frontend\node_modules\clientjs\src\vendor\deployJava.js:1150:21) at Object.writePluginTag (C:\projects\web-ssd-cms-api-bakcend\web-ssd-website-frontend\node_modules\clientjs\src\vendor\deployJava.js:1365:24) at Object.<anonymous> (C:\projects\web-ssd-cms-api-bakcend\web-ssd-website-frontend\node_modules\clientjs\src\vendor\deployJava.js:1423:12) at Module._compile (internal/modules/cjs/loader.js:1063:30) 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> (C:\projects\web-ssd-cms-api-bakcend\web-ssd-website-frontend\node_modules\clientjs\src\modules\java-detection.js:3:18) { type: ‘ReferenceError’ }

Even if one puts try catch on the block it still does this, because the issue is in import method. It tries to do something with navigator import time, but I believe it should do anything only when new ClientJS is called

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:6
  • Comments:5

github_iconTop GitHub Comments

3reactions
hacknlovecommented, Apr 22, 2022

You can create a component that you can import and use dynamically

The component:

import { ClientJS  } from 'clientjs'
import { useEffect } from 'react';

export default function ClientJsComponent({ setFingerPrint }) {
  useEffect(() => {
    const client = new ClientJS();
    const fingerprint = client.getFingerprint();
    setFingerPrint(fingerprint);
  }, [])

  return null
}

How to use it

import { useState } from 'react';
import dynamic from 'next/dynamic'

const ClientJs = dynamic(() => import('./components/ClientJs'), { ssr: false });

export default function Page () {
  const [fingerPrint, setFingerPrint] = useState()
  
  return (
    <>
        {fingerPrint}
        <ClientJs setFingerPrint={setFingerPrint} />
    </>
 )
}

Maybe it’s not elegant, but it might do it.

Another option is to copy the ClientJs min script to public, load it with <Script src="/ClientJS.min.js" onLoad={doSomething} /> and run a functión when it’s ready

1reaction
praty22commented, Apr 14, 2022

Didn’t work for me, Falling back to fingerprintJs. Thanks for the quick response.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · vercel/next.js - GitHub
Issues list · next/font bug when code is instrumented · dynamic fetching with prisma · Next. · Dynamic routes react router returns undefined...
Read more >
module-not-found - Next.js
The module you're trying to import uses Node.js specific modules, for example dns , outside of getStaticProps / getStaticPaths / getServerSideProps. Possible ...
Read more >
Nextjs stuck loading the home page - Stack Overflow
js dev server gets stuck after a while, requests just spin) issue, there are several approaches. I problem was solved by changing the...
Read more >
5 Most Commonly error face is Next.js? | Nextjs - Medium
This error occurs due to the unclosing tag. in reactjs, everything is based on the open and closing tag. When do not close...
Read more >
Troubleshooting for Next.js - Sentry Documentation
If you need help solving issues with your Sentry JavaScript SDK integration, you can read the edge cases documented below. If you need...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found