window is no defined
Unanswered
American black bear posted this in #help-forum
American black bearOP
I am trying to use react-mic npm package in my next js project. But it every time tell me window is not defined. How can I fix this?
37 Replies
Dunker
show code and error
American black bearOP
Dunker
what that red line says at import line
American black bearOP
'ReactMic' is declared but its value is never read.ts(6133)
Could not find a declaration file for module 'react-mic'. 'e:/React/Roshan Pera/brainwave-frontend-copy/node_modules/react-mic/dist/index.js' implicitly has an 'any' type.
Try
Could not find a declaration file for module 'react-mic'. 'e:/React/Roshan Pera/brainwave-frontend-copy/node_modules/react-mic/dist/index.js' implicitly has an 'any' type.
Try
Could not find a declaration file for module 'react-mic'. 'e:/React/Roshan Pera/brainwave-frontend-copy/node_modules/react-mic/dist/index.js' implicitly has an 'any' type.
Try
npm i --save-dev @types/react-mic if it exists or add a new declaration (.d.ts) file containing declare module 'react-mic';ts(7016)Could not find a declaration file for module 'react-mic'. 'e:/React/Roshan Pera/brainwave-frontend-copy/node_modules/react-mic/dist/index.js' implicitly has an 'any' type.
Try
npm i --save-dev @types/react-mic if it exists or add a new declaration (.d.ts) file containing declare module 'react-mic';ts(7016)Dunker
first run this
npm i --save-dev @types/react-mic
before stop terminal
American black bearOP
npm i --save-dev @types/react-mic
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: react-ga@2.7.0
npm WARN Found: react@18.2.0
npm WARN node_modules/react
npm WARN peer react@">=18" from @chakra-ui/color-mode@2.1.11
npm WARN node_modules/@chakra-ui/color-mode
npm WARN @chakra-ui/color-mode@"^2.1.11" from the root project
npm WARN 38 more (@chakra-ui/react-use-safe-layout-effect, ...)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer react@"^15.6.2 ^16.0" from react-ga@2.7.0
npm WARN node_modules/react-ga
npm WARN react-ga@"^2.2.0" from react-mic@12.4.6
npm WARN node_modules/react-mic
npm WARN
npm WARN Conflicting peer dependency: react@16.14.0
npm WARN node_modules/react
npm WARN peer react@"^15.6.2 ^16.0" from react-ga@2.7.0
npm WARN node_modules/react-ga
npm WARN react-ga@"^2.2.0" from react-mic@12.4.6
npm WARN node_modules/react-mic
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: react-mic@12.4.6
npm ERR! Found: react@18.2.0
npm ERR! node_modules/react
npm ERR! peer react@">=18" from @chakra-ui/color-mode@2.1.11
npm ERR! node_modules/@chakra-ui/color-mode
npm ERR! @chakra-ui/color-mode@"^2.1.11" from the root project
npm ERR! peer react@">=18" from @chakra-ui/react-use-safe-layout-effect@2.0.4
npm ERR! node_modules/@chakra-ui/react-use-safe-layout-effect
npm ERR! @chakra-ui/react-use-safe-layout-effect@"2.0.4" from @chakra-ui/color-mode@2.1.11
npm ERR! node_modules/@chakra-ui/color-mode
npm ERR! @chakra-ui/color-mode@"^2.1.11" from the root project
npm ERR! 37 more (@emoji-mart/react, @emotion/react, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"16.x" from react-mic@12.4.6
npm ERR! node_modules/react-mic
npm ERR! react-mic@"^12.4.6" from the root project
npm ERR!
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: react-ga@2.7.0
npm WARN Found: react@18.2.0
npm WARN node_modules/react
npm WARN peer react@">=18" from @chakra-ui/color-mode@2.1.11
npm WARN node_modules/@chakra-ui/color-mode
npm WARN @chakra-ui/color-mode@"^2.1.11" from the root project
npm WARN 38 more (@chakra-ui/react-use-safe-layout-effect, ...)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer react@"^15.6.2 ^16.0" from react-ga@2.7.0
npm WARN node_modules/react-ga
npm WARN react-ga@"^2.2.0" from react-mic@12.4.6
npm WARN node_modules/react-mic
npm WARN
npm WARN Conflicting peer dependency: react@16.14.0
npm WARN node_modules/react
npm WARN peer react@"^15.6.2 ^16.0" from react-ga@2.7.0
npm WARN node_modules/react-ga
npm WARN react-ga@"^2.2.0" from react-mic@12.4.6
npm WARN node_modules/react-mic
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: react-mic@12.4.6
npm ERR! Found: react@18.2.0
npm ERR! node_modules/react
npm ERR! peer react@">=18" from @chakra-ui/color-mode@2.1.11
npm ERR! node_modules/@chakra-ui/color-mode
npm ERR! @chakra-ui/color-mode@"^2.1.11" from the root project
npm ERR! peer react@">=18" from @chakra-ui/react-use-safe-layout-effect@2.0.4
npm ERR! node_modules/@chakra-ui/react-use-safe-layout-effect
npm ERR! @chakra-ui/react-use-safe-layout-effect@"2.0.4" from @chakra-ui/color-mode@2.1.11
npm ERR! node_modules/@chakra-ui/color-mode
npm ERR! @chakra-ui/color-mode@"^2.1.11" from the root project
npm ERR! 37 more (@emoji-mart/react, @emotion/react, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"16.x" from react-mic@12.4.6
npm ERR! node_modules/react-mic
npm ERR! react-mic@"^12.4.6" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: react@16.14.0
npm ERR! node_modules/react
npm ERR! peer react@"16.x" from react-mic@12.4.6
npm ERR! node_modules/react-mic
npm ERR! react-mic@"^12.4.6" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! C:\Users\Md Omor Faruk\AppData\Local\npm-cache_logs\2023-11-13T19_20_54_858Z-eresolve-report.txt
npm ERR! A complete log of this run can be found in: C:\Users\Md Omor Faruk\AppData\Local\npm-cache_logs\2023-11-13T19_20_54_858Z-debug-0.log
npm ERR! node_modules/react
npm ERR! peer react@"16.x" from react-mic@12.4.6
npm ERR! node_modules/react-mic
npm ERR! react-mic@"^12.4.6" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! C:\Users\Md Omor Faruk\AppData\Local\npm-cache_logs\2023-11-13T19_20_54_858Z-eresolve-report.txt
npm ERR! A complete log of this run can be found in: C:\Users\Md Omor Faruk\AppData\Local\npm-cache_logs\2023-11-13T19_20_54_858Z-debug-0.log
Dunker
use
--forceretry
npm ERR! this command with --force
npm ERR! this command with --force
American black bearOP
It installed
But the error is same
Window is not defined
Dunker
are you using
use client at top of filetry render the Mic component only when window is not undefined
{typeof window !== 'undefined' && <Mic />}@Dunker are you using `use client` at top of file
American black bearOP
yes
or use dynamic import without ssr
https://nextjs.org/docs/app/building-your-application/optimizing/lazy-loading#skipping-ssr
https://nextjs.org/docs/app/building-your-application/optimizing/lazy-loading#skipping-ssr
@Ray try render the Mic component only when window is not undefined
js
{typeof window !== 'undefined' && <Mic />}
American black bearOP
Not working!
@Ray or use dynamic import without ssr
https://nextjs.org/docs/app/building-your-application/optimizing/lazy-loading#skipping-ssr
American black bearOP
I have try this. But not working!
Dunker
this shouldnt happen
@Dunker this shouldnt happen
American black bearOP
Is there any solution?
https://codesandbox.io/s/sharp-driscoll-gu31yh?file=/src/index.js
I am creating just recording part like this in next.js
I am creating just recording part like this in next.js
dynamic import work for me
@Ray dynamic import work for me
American black bearOP
do you try with react-mic package?
yes
well use dynamic import with your Mic component
American black bearOP
may you give a screenshot
American black bearOP
Thank you bro
It working, but when I refresh it tell me window is undefind. Is there any way to solve this?
I don't get that error when refreshing
not sure how you are using it
American black bearOP
you missing {ssr: false}
American black bearOP
Thak you bro
Thak you very much