So far in 2 projects I created a .env file in the root of my project. I install npm install dotenv. I place (e.g.)REACT_APP_KEY='123456' in the env file . In my app.js file I add require("dotenv").config() in my component where I am making the api call i console.log(process.env.REACT_APP_KEY) in the the console I get 123456. So far it looks like its working. But when I place the process.env.REACT_APP_KEY in the api call I get 404 error? What am i missing? If I remove process.env.REACT_APP_KEY and add 123456, I get no error and the call works. Is it because I am using axios to get the data, should i use fetch? I can't seem to find anything that can help me with this. I included my error below.
thank you.
xhr.js:177 GET https://api.unsplash.com/search/photos?query=bali 401
dispatchXhrRequest # xhr.js:177
xhrAdapter # xhr.js:13
dispatchRequest # dispatchRequest.js:52
Promise.then (async)
request # Axios.js:61
Axios.<computed> # Axios.js:76
wrap # bind.js:9
getImages # App.js:12
onSearchSubmit # App.js:20
App # App.js:22
renderWithHooks # react-dom.development.js:14985
mountIndeterminateComponent # react-dom.development.js:17811
beginWork # react-dom.development.js:19049
beginWork$1 # react-dom.development.js:23940
performUnitOfWork # react-dom.development.js:22776
workLoopSync # react-dom.development.js:22707
renderRootSync # react-dom.development.js:22670
performSyncWorkOnRoot # react-dom.development.js:22293
scheduleUpdateOnFiber # react-dom.development.js:21881
updateContainer # react-dom.development.js:25482
(anonymous) # react-dom.development.js:26021
unbatchedUpdates # react-dom.development.js:22431
legacyRenderSubtreeIntoContainer # react-dom.development.js:26020
render # react-dom.development.js:26103
(anonymous) # index.js:7
./src/index.js # index.js:18
__webpack_require__ # bootstrap:856
fn # bootstrap:150
1 # reportWebVitals.js:14
__webpack_require__ # bootstrap:856
checkDeferredModules # bootstrap:45
webpackJsonpCallback # bootstrap:32
(anonymous) # main.chunk.js:1
createError.js:16 Uncaught (in promise) Error: Request failed with status code 401
at createError (createError.js:16)
at settle (settle.js:17)
at XMLHttpRequest.handleLoad (xhr.js:62)
Related
It's my first time working with a technology in beta so maybe this is to be expected and I should just ignore these erros for now?
I'm also extremely new to Next.js.
I've ran npx create-next-app#latest front --typescript - to create a new directory for my app code (will keep my API separated as there's also an electron app that needs to communicate with it).
I chose no for using the src/ directory.
I chose yes for the experimental /app directory.
I simply clicked enter and skipped when asked about configuring an import alias.
When the project was built, I ran npm run dev and I am getting 3 errors out of the box.
Errors are-
Two of this:
Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Expected server HTML to contain a matching <main> in <body>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error
One of this:
Error: There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.
This is the complete log from the console:
at main
at ScrollAndFocusHandler (webpack-internal:///(app-client)/./node_modules/next/dist/client/components/layout-router.js:149:1)
at InnerLayoutRouter (webpack-internal:///(app-client)/./node_modules/next/dist/client/components/layout-router.js:178:11)
at RedirectErrorBoundary (webpack-internal:///(app-client)/./node_modules/next/dist/client/components/layout-router.js:334:9)
at RedirectBoundary (webpack-internal:///(app-client)/./node_modules/next/dist/client/components/layout-router.js:341:11)
at NotFoundErrorBoundary (webpack-internal:///(app-client)/./node_modules/next/dist/client/components/layout-router.js:370:9)
at NotFoundBoundary (webpack-internal:///(app-client)/./node_modules/next/dist/client/components/layout-router.js:377:11)
at LoadingBoundary (webpack-internal:///(app-client)/./node_modules/next/dist/client/components/layout-router.js:289:11)
at ErrorBoundary (webpack-internal:///(app-client)/./node_modules/next/dist/client/components/error-boundary.js:76:11)
at RenderFromTemplateContext (webpack-internal:///(app-client)/./node_modules/next/dist/client/components/render-from-template-context.js:12:34)
at OuterLayoutRouter (webpack-internal:///(app-client)/./node_modules/next/dist/client/components/layout-router.js:20:11)
at body
at html
at ReactDevOverlay (webpack-internal:///(app-client)/./node_modules/next/dist/client/components/react-dev-overlay/internal/ReactDevOverlay.js:58:9)
at HotReload (webpack-internal:///(app-client)/./node_modules/next/dist/client/components/react-dev-overlay/hot-reloader-client.js:19:11)
at Router (webpack-internal:///(app-client)/./node_modules/next/dist/client/components/app-router.js:99:11)
at ErrorBoundaryHandler (webpack-internal:///(app-client)/./node_modules/next/dist/client/components/error-boundary.js:63:9)
at ErrorBoundary (webpack-internal:///(app-client)/./node_modules/next/dist/client/components/error-boundary.js:76:11)
at AppRouter (webpack-internal:///(app-client)/./node_modules/next/dist/client/components/app-router.js:20:13)
at ServerRoot (webpack-internal:///(app-client)/./node_modules/next/dist/client/app-index.js:126:11)
at RSCComponent
at Root (webpack-internal:///(app-client)/./node_modules/next/dist/client/app-index.js:143:11)
overrideMethod # react_devtools_backend.js:4012
console.error # hydration-error-info.js?32aa:24
printWarning # react-dom.development.js?d37d:94
error # react-dom.development.js?d37d:68
warnForInsertedHydratedElement # react-dom.development.js?d37d:10659
didNotFindHydratableInstance # react-dom.development.js?d37d:13436
warnNonhydratedInstance # react-dom.development.js?d37d:14601
tryToClaimNextHydratableInstance # react-dom.development.js?d37d:14775
updateHostComponent # react-dom.development.js?d37d:23001
beginWork # react-dom.development.js?d37d:24831
beginWork$1 # react-dom.development.js?d37d:32185
performUnitOfWork # react-dom.development.js?d37d:31082
workLoopConcurrent # react-dom.development.js?d37d:31068
renderRootConcurrent # react-dom.development.js?d37d:31026
performConcurrentWorkOnRoot # react-dom.development.js?d37d:29983
workLoop # index.js?91dc:10
flushWork # index.js?91dc:10
performWorkUntilDeadline # index.js?91dc:10
react-dom.development.js?d37d:14726 Uncaught Error: Hydration failed because the initial UI does not match what was rendered on the server.
at throwOnHydrationMismatch (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:14726:9)
at tryToClaimNextHydratableInstance (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:14776:7)
at updateHostComponent (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:22996:5)
at beginWork (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:24826:14)
at HTMLUnknownElement.callCallback (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:4246:14)
at Object.invokeGuardedCallbackDev (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:4295:16)
at invokeGuardedCallback (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:4359:31)
at beginWork$1 (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:32202:7)
at performUnitOfWork (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:31077:12)
at workLoopConcurrent (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:31063:5)
at renderRootConcurrent (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:31021:7)
at performConcurrentWorkOnRoot (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:29978:38)
at workLoop (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/scheduler/index.js:11:3897)
at flushWork (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/scheduler/index.js:11:3606)
at MessagePort.performWorkUntilDeadline (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/scheduler/index.js:11:1787)
throwOnHydrationMismatch # react-dom.development.js?d37d:14726
tryToClaimNextHydratableInstance # react-dom.development.js?d37d:14776
updateHostComponent # react-dom.development.js?d37d:23001
beginWork # react-dom.development.js?d37d:24831
callCallback # react-dom.development.js?d37d:4246
invokeGuardedCallbackDev # react-dom.development.js?d37d:4295
invokeGuardedCallback # react-dom.development.js?d37d:4359
beginWork$1 # react-dom.development.js?d37d:32207
performUnitOfWork # react-dom.development.js?d37d:31082
workLoopConcurrent # react-dom.development.js?d37d:31068
renderRootConcurrent # react-dom.development.js?d37d:31026
performConcurrentWorkOnRoot # react-dom.development.js?d37d:29983
workLoop # index.js?91dc:10
flushWork # index.js?91dc:10
performWorkUntilDeadline # index.js?91dc:10
react_devtools_backend.js:4012 Warning: An error occurred during hydration. The server HTML was replaced with client content in <#document>.
overrideMethod # react_devtools_backend.js:4012
console.error # hydration-error-info.js?32aa:24
printWarning # react-dom.development.js?d37d:94
error # react-dom.development.js?d37d:68
errorHydratingContainer # react-dom.development.js?d37d:13451
recoverFromConcurrentError # react-dom.development.js?d37d:30105
performConcurrentWorkOnRoot # react-dom.development.js?d37d:29996
workLoop # index.js?91dc:10
flushWork # index.js?91dc:10
performWorkUntilDeadline # index.js?91dc:10
react_devtools_backend.js:4012 Warning: You are accessing "digest" from the errorInfo object passed to onRecoverableError. This property is deprecated and will be removed in a future version of React. To access the digest of an Error look for this property on the Error instance itself.
overrideMethod # react_devtools_backend.js:4012
console.error # hydration-error-info.js?32aa:24
printWarning # react-dom.development.js?d37d:94
error # react-dom.development.js?d37d:68
get # react-dom.development.js?d37d:31630
onRecoverableError # on-recoverable-error.js?eb92:8
commitRootImpl # react-dom.development.js?d37d:31567
commitRoot # react-dom.development.js?d37d:31330
finishConcurrentRender # react-dom.development.js?d37d:30263
performConcurrentWorkOnRoot # react-dom.development.js?d37d:30055
workLoop # index.js?91dc:10
flushWork # index.js?91dc:10
performWorkUntilDeadline # index.js?91dc:10
on-recoverable-error.js?eb92:17 Uncaught Error: Hydration failed because the initial UI does not match what was rendered on the server.
at throwOnHydrationMismatch (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:14726:9)
at tryToClaimNextHydratableInstance (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:14776:7)
at updateHostComponent (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:22996:5)
at beginWork (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:24826:14)
at beginWork$1 (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:32180:14)
at performUnitOfWork (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:31077:12)
at workLoopConcurrent (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:31063:5)
at renderRootConcurrent (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:31021:7)
at performConcurrentWorkOnRoot (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:29978:38)
at workLoop (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/scheduler/index.js:11:3897)
at flushWork (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/scheduler/index.js:11:3606)
at MessagePort.performWorkUntilDeadline (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/scheduler/index.js:11:1787)
throwOnHydrationMismatch # react-dom.development.js?d37d:14726
tryToClaimNextHydratableInstance # react-dom.development.js?d37d:14776
updateHostComponent # react-dom.development.js?d37d:23001
beginWork # react-dom.development.js?d37d:24831
beginWork$1 # react-dom.development.js?d37d:32185
performUnitOfWork # react-dom.development.js?d37d:31082
workLoopConcurrent # react-dom.development.js?d37d:31068
renderRootConcurrent # react-dom.development.js?d37d:31026
performConcurrentWorkOnRoot # react-dom.development.js?d37d:29983
workLoop # index.js?91dc:10
flushWork # index.js?91dc:10
performWorkUntilDeadline # index.js?91dc:10
react_devtools_backend.js:4012 Warning: You are accessing "digest" from the errorInfo object passed to onRecoverableError. This property is deprecated and will be removed in a future version of React. To access the digest of an Error look for this property on the Error instance itself.
overrideMethod # react_devtools_backend.js:4012
console.error # hydration-error-info.js?32aa:24
printWarning # react-dom.development.js?d37d:94
error # react-dom.development.js?d37d:68
get # react-dom.development.js?d37d:31630
onRecoverableError # on-recoverable-error.js?eb92:8
commitRootImpl # react-dom.development.js?d37d:31567
commitRoot # react-dom.development.js?d37d:31330
finishConcurrentRender # react-dom.development.js?d37d:30263
performConcurrentWorkOnRoot # react-dom.development.js?d37d:30055
workLoop # index.js?91dc:10
flushWork # index.js?91dc:10
performWorkUntilDeadline # index.js?91dc:10
on-recoverable-error.js?eb92:17 Uncaught Error: Hydration failed because the initial UI does not match what was rendered on the server.
at throwOnHydrationMismatch (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:14726:9)
at tryToClaimNextHydratableInstance (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:14776:7)
at updateHostComponent (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:22996:5)
at beginWork (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:24826:14)
at beginWork$1 (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:32180:14)
at performUnitOfWork (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:31077:12)
at workLoopConcurrent (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:31063:5)
at renderRootConcurrent (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:31021:7)
at performConcurrentWorkOnRoot (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:29978:38)
at workLoop (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/scheduler/index.js:11:3897)
at flushWork (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/scheduler/index.js:11:3606)
at MessagePort.performWorkUntilDeadline (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/scheduler/index.js:11:1787)
throwOnHydrationMismatch # react-dom.development.js?d37d:14726
tryToClaimNextHydratableInstance # react-dom.development.js?d37d:14776
updateHostComponent # react-dom.development.js?d37d:23001
beginWork # react-dom.development.js?d37d:24831
beginWork$1 # react-dom.development.js?d37d:32185
performUnitOfWork # react-dom.development.js?d37d:31082
workLoopConcurrent # react-dom.development.js?d37d:31068
renderRootConcurrent # react-dom.development.js?d37d:31026
performConcurrentWorkOnRoot # react-dom.development.js?d37d:29983
workLoop # index.js?91dc:10
flushWork # index.js?91dc:10
performWorkUntilDeadline # index.js?91dc:10
react_devtools_backend.js:4012 Warning: You are accessing "digest" from the errorInfo object passed to onRecoverableError. This property is deprecated and will be removed in a future version of React. To access the digest of an Error look for this property on the Error instance itself.
overrideMethod # react_devtools_backend.js:4012
console.error # hydration-error-info.js?32aa:24
printWarning # react-dom.development.js?d37d:94
error # react-dom.development.js?d37d:68
get # react-dom.development.js?d37d:31630
onRecoverableError # on-recoverable-error.js?eb92:8
commitRootImpl # react-dom.development.js?d37d:31567
commitRoot # react-dom.development.js?d37d:31330
finishConcurrentRender # react-dom.development.js?d37d:30263
performConcurrentWorkOnRoot # react-dom.development.js?d37d:30055
workLoop # index.js?91dc:10
flushWork # index.js?91dc:10
performWorkUntilDeadline # index.js?91dc:10
on-recoverable-error.js?eb92:17 Uncaught Error: Hydration failed because the initial UI does not match what was rendered on the server.
at throwOnHydrationMismatch (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:14726:9)
at tryToClaimNextHydratableInstance (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:14776:7)
at updateHostComponent (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:22996:5)
at beginWork (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:24826:14)
at beginWork$1 (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:32180:14)
at performUnitOfWork (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:31077:12)
at workLoopConcurrent (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:31063:5)
at renderRootConcurrent (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:31021:7)
at performConcurrentWorkOnRoot (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:29978:38)
at workLoop (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/scheduler/index.js:11:3897)
at flushWork (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/scheduler/index.js:11:3606)
at MessagePort.performWorkUntilDeadline (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/scheduler/index.js:11:1787)
throwOnHydrationMismatch # react-dom.development.js?d37d:14726
tryToClaimNextHydratableInstance # react-dom.development.js?d37d:14776
updateHostComponent # react-dom.development.js?d37d:23001
beginWork # react-dom.development.js?d37d:24831
beginWork$1 # react-dom.development.js?d37d:32185
performUnitOfWork # react-dom.development.js?d37d:31082
workLoopConcurrent # react-dom.development.js?d37d:31068
renderRootConcurrent # react-dom.development.js?d37d:31026
performConcurrentWorkOnRoot # react-dom.development.js?d37d:29983
workLoop # index.js?91dc:10
flushWork # index.js?91dc:10
performWorkUntilDeadline # index.js?91dc:10
react_devtools_backend.js:4012 Warning: You are accessing "digest" from the errorInfo object passed to onRecoverableError. This property is deprecated and will be removed in a future version of React. To access the digest of an Error look for this property on the Error instance itself.
overrideMethod # react_devtools_backend.js:4012
console.error # hydration-error-info.js?32aa:24
printWarning # react-dom.development.js?d37d:94
error # react-dom.development.js?d37d:68
get # react-dom.development.js?d37d:31630
onRecoverableError # on-recoverable-error.js?eb92:8
commitRootImpl # react-dom.development.js?d37d:31567
commitRoot # react-dom.development.js?d37d:31330
finishConcurrentRender # react-dom.development.js?d37d:30263
performConcurrentWorkOnRoot # react-dom.development.js?d37d:30055
workLoop # index.js?91dc:10
flushWork # index.js?91dc:10
performWorkUntilDeadline # index.js?91dc:10
react-dom.development.js?d37d:22948 Uncaught Error: There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.
at updateHostRoot (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:22943:57)
at beginWork (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:24809:14)
at beginWork$1 (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:32180:14)
at performUnitOfWork (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:31077:12)
at workLoopSync (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:30886:5)
at renderRootSync (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:30851:7)
at recoverFromConcurrentError (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:30104:20)
at performConcurrentWorkOnRoot (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:29991:22)
at workLoop (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/scheduler/index.js:11:3897)
at flushWork (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/scheduler/index.js:11:3606)
at MessagePort.performWorkUntilDeadline (webpack-internal:///(:3000/app-client)/./node_modules/next/dist/compiled/scheduler/index.js:11:1787)```
I have used recipepuppy api and while fetching the items i'm unable to get the result and i keep on getting this error
the code is
search(){
let {ingredients, dish} = this.state;
const url =`http://www.recipepuppy.com/api/?i=${ingredients}&q=${dish}`;
fetch(url, {
method: 'GET'
}).then(response => response.json())
.then(json => console.log('recipes', json));
}
I'm getting this error in console as
SearchRecipes.js:17 GET http://www.recipepuppy.com/api/?i=garlic,chicken&q=adobo 500 (Internal Server Error)
search # SearchRecipes.js:17
onClick # SearchRecipes.js:49
callCallback # react-dom.development.js:189
invokeGuardedCallbackDev # react-dom.development.js:238
invokeGuardedCallback # react-dom.development.js:291
invokeGuardedCallbackAndCatchFirstError # react-dom.development.js:306
executeDispatch # react-dom.development.js:391
executeDispatchesInOrder # react-dom.development.js:416
executeDispatchesAndRelease # react-dom.development.js:3301
executeDispatchesAndReleaseTopLevel # react-dom.development.js:3310
forEachAccumulated # react-dom.development.js:3282
runEventsInBatch # react-dom.development.js:3327
runExtractedPluginEventsInBatch # react-dom.development.js:3537
handleTopLevel # react-dom.development.js:3581
batchedEventUpdates$1 # react-dom.development.js:21729
batchedEventUpdates # react-dom.development.js:798
dispatchEventForLegacyPluginEventSystem # react-dom.development.js:3591
attemptToDispatchEvent # react-dom.development.js:4311
dispatchEvent # react-dom.development.js:4232
unstable_runWithPriority # scheduler.development.js:659
runWithPriority$1 # react-dom.development.js:11077
discreteUpdates$1 # react-dom.development.js:21746
discreteUpdates # react-dom.development.js:811
dispatchDiscreteEvent # react-dom.development.js:4211
VM1141:1 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 91
please help me with this
The problem is not on your end, this API does not send the body data properly, and concatenates an HTML string onto a JSON response, hence you can't actually parse the response properly. If this isn't your API just contact the owner and let them know.
I am new to MERN stack and I am trying to build a login/registration system on the stack.
When I am trying to make a post request it is throwing this error:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'data')
at registrationHandler (Register.jsx:47:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
at invokeGuardedCallback (react-dom.development.js:4056:1)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4070:1)
at executeDispatch (react-dom.development.js:8243:1)
at processDispatchQueueItemsInOrder (react-dom.development.js:8275:1)
at processDispatchQueue (react-dom.development.js:8288:1)
at dispatchEventsForPlugins (react-dom.development.js:8299:1)
at react-dom.development.js:8508:1
registrationHandler # Register.jsx:47
callCallback # react-dom.development.js:3945
invokeGuardedCallbackDev # react-dom.development.js:3994
invokeGuardedCallback # react-dom.development.js:4056
invokeGuardedCallbackAndCatchFirstError # react-dom.development.js:4070
executeDispatch # react-dom.development.js:8243
processDispatchQueueItemsInOrder # react-dom.development.js:8275
processDispatchQueue # react-dom.development.js:8288
dispatchEventsForPlugins # react-dom.development.js:8299
(anonymous) # react-dom.development.js:8508
batchedEventUpdates$1 # react-dom.development.js:22396
batchedEventUpdates # react-dom.development.js:3745
dispatchEventForPluginEventSystem # react-dom.development.js:8507
attemptToDispatchEvent # react-dom.development.js:6005
dispatchEvent # react-dom.development.js:5924
unstable_runWithPriority # scheduler.development.js:468
runWithPriority$1 # react-dom.development.js:11276
discreteUpdates$1 # react-dom.development.js:22413
discreteUpdates # react-dom.development.js:3756
dispatchDiscreteEvent # react-dom.development.js:5889
My code is as follows:
This is being called on Form Submit
When I am making the same request from Postman it happens successfully:
Please any help is appreciated...
I was importing Axios as
import { axios } from 'axios'
which should be
import axios from 'axios'.
Also, history.push() was replaced by useNavigate('/') in v6 of react-router-dom.
Lastly at line 30, it should be data.data.token.
I use Chrome as my default browser. I have cross origins configured in my Spring backend and React front end.
Spring: #CrossOrigin(origins = "http://localhost:3000")
React: const USER_API_BASE_URL = "http://localhost:8080/api/v1/users";
All works great when I am working on my PC. I configured NOIP and configured my router to route incoming to my development PC. When I start a session using the external address I get the CORS error:
...
Access to XMLHttpRequest at 'http://localhost:8080/api/v1/users' from origin 'http://TESTURL.ddns.net:3000' has been blocked by CORS policy: The request client is not a secure context and the resource is in more-private address space `local`.
xhr.js:187 GET http://localhost:8080/api/v1/users net::ERR_FAILED
dispatchXhrRequest # xhr.js:187
xhrAdapter # xhr.js:13
dispatchRequest # dispatchRequest.js:53
request # Axios.js:108
Axios.<computed> # Axios.js:129
wrap # bind.js:9
getUsers # UserService.js:8
componentDidMount # LoginComponent.jsx:19
commitLifeCycles # react-dom.development.js:19816
commitLayoutEffects # react-dom.development.js:22805
callCallback # react-dom.development.js:188
invokeGuardedCallbackDev # react-dom.development.js:237
invokeGuardedCallback # react-dom.development.js:292
commitRootImpl # react-dom.development.js:22543
unstable_runWithPriority # scheduler.development.js:653
runWithPriority$1 # react-dom.development.js:11039
commitRoot # react-dom.development.js:22383
finishSyncRender # react-dom.development.js:21809
performSyncWorkOnRoot # react-dom.development.js:21795
scheduleUpdateOnFiber # react-dom.development.js:21190
updateContainer # react-dom.development.js:24375
(anonymous) # react-dom.development.js:24760
unbatchedUpdates # react-dom.development.js:21905
legacyRenderSubtreeIntoContainer # react-dom.development.js:24759
render # react-dom.development.js:24842
(anonymous) # index.js:8
./src/index.js # index.js:19
__webpack_require__ # bootstrap:856
fn # bootstrap:150
1 # reportWebVitals.js:14
__webpack_require__ # bootstrap:856
checkDeferredModules # bootstrap:45
webpackJsonpCallback # bootstrap:32
(anonymous) # main.chunk.js:1
Show 4 more frames
createError.js:16 Uncaught (in promise) Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:99)
...
Is there a way around this?
The solution was
In the React front end changing
const USER_API_BASE_URL = "http://localhost:8080/api/v1/documenttype";
to
const USER_API_BASE_URL = "http://XXsystem.ddns.net:8080/api/v1/documenttype";
In the Spring backend changing
#CrossOrigin("http://localhost:3000")
to
#CrossOrigin(origins = "http://XXsystem.ddns.net:3000")
Interesting that the 'localhost testing still work !
Best of both worlds.
I am trying to access a spring boot micro-service hosting on localhost but I am getting following error:
Uncaught (in promise) Error: Request failed with status code 400
Following is my code to access the service:
import axios from "axios";
export const addProjectTask = (project_task, history) => async dispatch => {
await axios.post("http://localhost:8080/api/board", project_task);
history.push("/");
};
I have tried to search on the internet but I am not able to find any solution with the localhost. When I use the above URL in Postman it works fine so the URL is correct.
Edit:
Complete Error:
xhr.js:178 POST http://localhost:8080/api/board 400
dispatchXhrRequest # xhr.js:178
xhrAdapter # xhr.js:12
dispatchRequest # dispatchRequest.js:52
Promise.then (async)
request # Axios.js:61
Axios.<computed> # Axios.js:86
wrap # bind.js:9
(anonymous) # projectTaskActions.js:4
(anonymous) # index.js:8
(anonymous) # redux.js:477
onSubmit # AddProjectTask.js:31
callCallback # react-dom.development.js:188
invokeGuardedCallbackDev # react-dom.development.js:237
invokeGuardedCallback # react-dom.development.js:292
invokeGuardedCallbackAndCatchFirstError # react-dom.development.js:306
executeDispatch # react-dom.development.js:389
executeDispatchesInOrder # react-dom.development.js:414
executeDispatchesAndRelease # react-dom.development.js:3278
executeDispatchesAndReleaseTopLevel # react-dom.development.js:3287
forEachAccumulated # react-dom.development.js:3259
runEventsInBatch # react-dom.development.js:3304
runExtractedPluginEventsInBatch # react-dom.development.js:3514
handleTopLevel # react-dom.development.js:3558
batchedEventUpdates$1 # react-dom.development.js:21871
batchedEventUpdates # react-dom.development.js:795
dispatchEventForLegacyPluginEventSystem # react-dom.development.js:3568
attemptToDispatchEvent # react-dom.development.js:4267
dispatchEvent # react-dom.development.js:4189
unstable_runWithPriority # scheduler.development.js:653
runWithPriority$1 # react-dom.development.js:11039
discreteUpdates$1 # react-dom.development.js:21887
discreteUpdates # react-dom.development.js:806
dispatchDiscreteEvent # react-dom.development.js:4168