TypeError: Cannot read properties of undefined (reading 'sodium')
Unanswered
Cornish Rex posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
Hey, there. I'm getting this error while running the build command. I checked the Next.js repo Issues and Stackoverflow but didn't find much.
Interestingly, this path is not a page but a route handler.
This happened after upgrading from Next.js 13 to 14.
I would appreciate any help. š
Collecting page data .TypeError: Cannot read properties of undefined (reading 'sodium')
...
> Build error occurred
Error: Failed to collect page data for /checkout/order/[orderId]/callback/login
Interestingly, this path is not a page but a route handler.
This happened after upgrading from Next.js 13 to 14.
- "next": "13.5.6",
+ "next": "14.1.1",
I would appreciate any help. š
62 Replies
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
Was this working perfectly in next13?
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
@Siamese , yep. It was.
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
Have you tried removing node_modules and reinstalling all the dependeinces?
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
@Siamese , I did. It is also happening in CI.
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
It would be more helpful if you share your whole error log
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
@Cornish Rex
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
Sure thing.
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
I don't think it will work but worth a try.
remove .next folder from your directory. and build again
remove .next folder from your directory. and build again
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
@Siamese . Trying ...
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Great golden digger wasp
I just read all of your chat maybe it is happening because of cache.
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
@Siamese, same thing.
@Great golden digger wasp, after removing the
@Great golden digger wasp, after removing the
/.next
, directory is there any other cache I should be aware of?![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Great golden digger wasp
no
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
Are you able to run the project on development mode?
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
@Siamese, yep. Actually I found it in CI.
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
Can you build the project locally?
I think you will need to clear the cache of the server as well
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Great golden digger wasp
Are you using same node js version locally and on production server?
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
Can you build the project locally?@Siamese, no. It reproduces locally.
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Great golden digger wasp
?
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
Are you using same node js version locally and on production server?@Great golden digger wasp, yep.
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Great golden digger wasp
maybe you should run this command:
npm ls sodium
npm ls sodium
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
maybe you should run this command:@Great golden digger wasp, I will in an hour. Iām AFK now.
npm ls sodium
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Great golden digger wasp
ok
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
/api/2023-06-09/checkout/orders/[orderIdentifier]/update-buyer
Do you have this API route in your project?
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
Do you have this API route in your project?@Siamese, yep. As a route handler.
route.ts
.![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
ping me when you are on your computer. as @Great golden digger wasp it can be the issue with the sodium library itself
That API route is mentioned in the logs. maybe the app needs sodium library for that route. can not say anything without looking at the code of that route š
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
maybe you should run this command:@Great golden digger wasp.
npm ls sodium
update-next-app# pnpm ls sodium
update-next-app# echo $?
0
ping me when you are on your computer. as @Duraid Mustafa it can be the issue with the sodium library itself@Siamese, back to keyboard. I appreciate your patience. š
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
please use npm. I am not sure if pnpm works the same way with ls
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
@Siamese.
update-next-app# npm ls sodium
crossmint-monorepo@ /Users/juliojordan/update-next-app
āāā (empty)
update-next-app# echo $?
1
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
Can you search in your code base for "sodium" (without the quotes)
I found this sodium library https://github.com/paixaop/node-sodium#readme
Last commit was 5 years ago
Last commit was 5 years ago
@Cornish Rex Just for debugging purposes
Delete files associated with route
Delete files associated with route
/api/2023-06-09/checkout/orders/[orderIdentifier]/update-buyer
. and then build again.I was looking at the [migration guide](https://nextjs.org/docs/app/building-your-application/upgrading/version-14) from next 13 to 14
I hope you have upgraded your nextjs with the following command
Also If you are using TypeScript, ensure you also upgrade
I hope you have upgraded your nextjs with the following command
pnpm up next react react-dom eslint-config-next --latest
Also If you are using TypeScript, ensure you also upgrade
@types/react
and @types/react-dom
to their latest versions.![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
@Siamese, interesting. Thx! Give me 30 minutes. I'm joining a meeting right now. I'm sorry for the inconvenience.
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
Can you search in your code base for "sodium" (without the quotes)@Siamese.
update-next-app# grep sodium pnpm-lock.yaml
libsodium-wrappers@0.7.13:
libsodium@0.7.13:
libsodium-wrappers: 0.7.13
libsodium-wrappers@0.7.13:
libsodium: 0.7.13
libsodium@0.7.13: {}
update-next-app# ack --ts libsodium .
update-next-app# echo $?
1
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
What about this
and this
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
I hope you have upgraded your nextjs with the following command.@Siamese, yep. I followed the docs.
Delete files associated with route@Siamese, I got the same error but from other path. š/api/2023-06-09/checkout/orders/[orderIdentifier]/update-buyer
and then build again.
TypeError: Cannot read properties of undefined (reading 'sodium')
Build error occurred
Error: Failed to collect page data for /api/2023-06-09/checkout/orders
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
Do you have middlewear in your project?
Please Search for "sodium" in your entire codebase (not just in pnpm-lock file)
Share the codeblocks where the
sodium
is appearing![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
Please Search for "sodium" in your entire codebase (not just in pnpm-lock file)@Siamese.
update-next-app# grep --exclude-dir=./apps/crossmint-nextjs/.next --recursive sodium .
./pnpm-lock.yaml: libsodium-wrappers@0.7.13:
./pnpm-lock.yaml: libsodium@0.7.13:
./pnpm-lock.yaml: libsodium-wrappers: 0.7.13
./pnpm-lock.yaml: libsodium-wrappers@0.7.13:
./pnpm-lock.yaml: libsodium: 0.7.13
./pnpm-lock.yaml: libsodium@0.7.13: {}
update-next-app# $?
0
Do you have middlewear in your project?@Siamese, an auth middleware.
export async function middleware(request: NextRequest) {
if (["/console", "/alpha", "/user"].some((path) => request.nextUrl.pathname.startsWith(path))) {
return authRequestMiddleware(request);
}
return NextResponse.next();
}
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
If your development server is working perfectly fine but not the build. generally the problem is related to caching
Can you test something
Start the project in development mode
Open pages that are fetching data from route
/api/2023-06-09/checkout/orders/[orderIdentifier]/update-buyer
or the other routes that were mentioned in the errorI do not see any problem in your middleware, and there is no sodium in your code base as well.
What node version you are using?
Found this issue.
https://github.com/vercel/next.js/issues/61995 (updated)
https://github.com/vercel/next.js/issues/61995 (updated)
Just realized you need to run
pnpm store prune
to clean pnpm cache![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
What node version you are using?@Siamese.
update-next-app# node --version
v20.12.2
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
![Image](https://cdn.discordapp.com/attachments/1266350969646485617/1266412663676735550/image.png?ex=66a50e33&is=66a3bcb3&hm=228a162bb7e435dd9049ef9c6acda236c6ff9a1987dcd89a95bd75c4f70f2f57&)
I think it would be a good idea to downgrade next.js
and wait for things to get stable
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
@Siamese, I appreciate all your help.
Unfortunatelly, there's a [security vulnerability](https://nvd.nist.gov/vuln/detail/cve-2024-34351) in Next.js 13 and no fix but upgrading to version 14.
Unfortunatelly, there's a [security vulnerability](https://nvd.nist.gov/vuln/detail/cve-2024-34351) in Next.js 13 and no fix but upgrading to version 14.
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
Is your codebase available on github?
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Cornish RexOP
@Siamese, not publicly. Its my company product.
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Siamese
Oh No problems. I can take a look in the codebase and try if you are able to share it with me somehow