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
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. (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. (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
Here is the thing, as I understand it, the lib is doing something on require and not on initialization by constructor.
Here is a working workaround
try {
// This is not working anyway else, it performs an action on require which is
// throwing error build time
const client = require('clientjs')
const browser = new client.ClientJS()
// The rest of the usage
}
catch () {
// Do nothing
}
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
Reacted by roxennnn, darktm, Vitalii and Yoko Hailemariam
You can use the dist/client.base.min.js as described in the docs. This should work without executing any code upon a require call/import. It also has the benefit of being much smaller without losing any functionality on modern browsers.
You can use the dist/client.base.min.js as described in the docs. This should work without executing any code upon a require call/import. It also has the benefit of being much smaller without losing any functionality on modern browsers.
Here is the thing, as I understand it, the lib is doing something on require and not on initialization by constructor. Here is a working workaround
try {
// This is not working anyway else, it performs an action on require which is
// throwing error build time
const client = require('clientjs')
const browser = new client.ClientJS()
// The rest of the usage
}
catch () {
// Do nothing
}
thanks this code works for me. It solves my "ReferenceError: navigator is not defined" error when I try to build the next.js application. this is how I implemented it... maybe it can help someone...
@BendingBender The problem with including a "pre-minified" JS code is that there's no solid way to verify whether the source and minified version match. This could be a serious risk for certain websites that deal with PII and financial data. Most of today's fav frameworks are webpack/vite based, and they have configs for minifications.
Not saying that the minified files in dist do anything malicious.
Activity
praty22 commentedon Apr 14, 2022
Faced the same issue, any help would be appreciated.
devgrigor commentedon Apr 14, 2022
Here is the thing, as I understand it, the lib is doing something on
requireand not oninitializationby constructor.Here is a working workaround
praty22 commentedon Apr 14, 2022
Didn't work for me,
Falling back to fingerprintJs.
Thanks for the quick response.
hacknlove commentedon Apr 22, 2022
You can create a component that you can import and use dynamically
The component:
How to use it
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 readyBendingBender commentedon Apr 22, 2022
You can use the
dist/client.base.min.jsas described in the docs. This should work without executing any code upon a require call/import. It also has the benefit of being much smaller without losing any functionality on modern browsers.sangnt-sysvpn commentedon Jul 17, 2023
thanks!! I have tried and succeeded.
git-sujon commentedon Dec 19, 2023
thanks this code works for me. It solves my "ReferenceError: navigator is not defined" error when I try to build the next.js application. this is how I implemented it... maybe it can help someone...
`
const onFinish = async (values: ILogin) => {
try {
const ClientJs = require("clientjs");
const client = new ClientJs.ClientJS();
};
`
ravi-ojha commentedon Mar 19, 2024
@BendingBender The problem with including a "pre-minified" JS code is that there's no solid way to verify whether the source and minified version match. This could be a serious risk for certain websites that deal with PII and financial data. Most of today's fav frameworks are webpack/vite based, and they have configs for minifications.
Not saying that the minified files in dist do anything malicious.
DevHeauk commentedon Apr 11, 2024
same issue
yutingzhao1991 commentedon Nov 11, 2024
same issue, clientjs should not access navigate during initialization.