Route Handler throws Error
Answered
American Sable posted this in #help-forum
American SableOP
I am trying to use Route Handler but getting a TypeError: s is not a function
Folder Structure in screenshot
Am using localisation with the [lang] folder
my one api "route"
getting squigly lines on Response.->json<-
type Error looks like this (full path redacted to "PATH")
Google sadly isn't very helpful alsways get "page" help but not "app"
Folder Structure in screenshot
Am using localisation with the [lang] folder
my one api "route"
export const dynamic = 'force-dynamic' // defaults to force-static
export async function POST(request: Request) {
const res = await fetch(process.env.RequestBaseURL + "/customerapi/AuthUser/", {
headers: {
'Content-Type': 'application/json',
},
})
const data = await request.json()
return Response.json({ data })
}getting squigly lines on Response.->json<-
type Error looks like this (full path redacted to "PATH")
TypeError: s is not a function
at "PATH"/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:37:5936
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async tX ("PATH"node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:37:5313)
at async rl ("PATH"node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:38:23339)
at async doRender ("PATH"node_modules/next/dist/server/base-server.js:1406:30)
at async cacheEntry.responseCache.get.routeKind ("PATH"node_modules/next/dist/server/base-server.js:1567:28)
at async DevServer.renderToResponseWithComponentsImpl ("PATH"node_modules/next/dist/server/base-server.js:1475:28)
at async DevServer.renderErrorToResponseImpl ("PATH"node_modules/next/dist/server/base-server.js:2106:24)
at async pipe.req.req ("PATH"node_modules/next/dist/server/base-server.js:1984:30)
at async DevServer.pipeImpl ("PATH"node_modules/next/dist/server/base-server.js:902:25)Google sadly isn't very helpful alsways get "page" help but not "app"
Answered by American Sable
nvm figured it out. somehow misunderstood that the ts/js file was the route name instead of RouteName/route.ts
3 Replies
American SableOP
current dependencies in case the error is there
"dependencies": {
"@formatjs/intl-localematcher": "^0.5.2",
"@fortawesome/pro-light-svg-icons": "^6.4.0",
"@fortawesome/pro-regular-svg-icons": "^6.4.2",
"@fortawesome/pro-solid-svg-icons": "^6.4.0",
"@fortawesome/pro-thin-svg-icons": "^6.4.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"@types/node": "20.4.2",
"@types/react": "18.2.15",
"@types/react-dom": "18.2.7",
"@types/react-modal": "^3.16.3",
"accept-language": "^3.0.18",
"accept-language-parser": "^1.5.0",
"bootstrap": "^5.3.2",
"clsx": "^2.0.0",
"eslint": "8.45.0",
"eslint-config-next": "^14",
"i18next": "^23.4.1",
"i18next-browser-languagedetector": "^7.1.0",
"i18next-resources-to-backend": "^1.1.4",
"iron-session": "^8.0.1",
"negotiator": "^0.6.3",
"next": "^14",
"next-i18next": "^14.0.0",
"nextjs-current-url": "^1.0.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-dropzone": "^14.2.3",
"react-i18next": "^13.0.3",
"react-modal": "^3.16.1",
"styled-components": "^6.0.8",
"styled-jsx": "^5.1.2",
"typescript": "^5"
}calling the route with a simple fetch
fetch("/api/AuthUser/", {
method: "POST",
credentials: "include",
body: formData
}).then(response => {
return response.json()
}).then(json => {
})American SableOP
nvm figured it out. somehow misunderstood that the ts/js file was the route name instead of RouteName/route.ts
Answer