ReferenceError: navigator is not defined
alexander-vashchuk opened this issue · 1 comments
alexander-vashchuk commented
I encountered an error in my Next.js React project while attempting to utilize the 'chalk' library. The error message I found in my Vercel logs was as follows:
ReferenceError: navigator is not defined
at (node_modules/chalk/source/vendor/supports-color/browser.js:3:57)
at (webpack/bootstrap:21:0)
at (node_modules/next/dist/esm/shared/lib/isomorphic/path.js:11:17)
at (webpack/runtime/jsonp chunk loading:34:0)
at (api/calceyProxy/[...calceyProxy]:middleware.js:1:17)
As far as I understand, it seems that 'chalk' can only be used on the client-side. How can I fix this error? Here are the versions of the libraries I'm using:
- "next": "^13.4.9"
- "chalk": "^5.0.1"
- "react": "^18.2.0"
Qix- commented
Please search next time: https://github.com/chalk/chalk/issues?q=navigator
This is a problem with whatever bundler you're using, not chalk. We're not doing anything shocking or non-standard here.