Next.js Discord

Discord Forum

TypeError: Cannot read properties of undefined (reading 'sodium')

Unanswered
Cornish Rex posted this in #help-forum
Open in Discord
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.
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

Siamese
Was this working perfectly in next13?
Cornish RexOP
@Siamese , yep. It was.
Siamese
Have you tried removing node_modules and reinstalling all the dependeinces?
Cornish RexOP
@Siamese , I did. It is also happening in CI.
Siamese
It would be more helpful if you share your whole error log
Siamese
@Cornish Rex
Cornish RexOP
Sure thing.
Siamese
I don't think it will work but worth a try.
remove .next folder from your directory. and build again
Cornish RexOP
@Siamese . Trying ...
Great golden digger wasp
I just read all of your chat maybe it is happening because of cache.
Cornish RexOP
@Siamese, same thing.
@Great golden digger wasp, after removing the /.next, directory is there any other cache I should be aware of?
Siamese
Are you able to run the project on development mode?
Cornish RexOP
@Siamese, yep. Actually I found it in CI.
Siamese
Can you build the project locally?
I think you will need to clear the cache of the server as well
Great golden digger wasp
Are you using same node js version locally and on production server?
Cornish RexOP
Can you build the project locally?
@Siamese, no. It reproduces locally.
Cornish RexOP
Are you using same node js version locally and on production server?
@Great golden digger wasp, yep.
Great golden digger wasp
maybe you should run this command:
npm ls sodium
Cornish RexOP
maybe you should run this command:
npm ls sodium
@Great golden digger wasp, I will in an hour. I’m AFK now.
Great golden digger wasp
ok
@Cornish Rex > Can you build the project locally? <@610860696023859210>, no. It reproduces locally.
Siamese
/api/2023-06-09/checkout/orders/[orderIdentifier]/update-buyer
Do you have this API route in your project?
Cornish RexOP
Do you have this API route in your project?
@Siamese, yep. As a route handler. route.ts.
Siamese
ping me when you are on your computer. as @Great golden digger wasp it can be the issue with the sodium library itself
@Cornish Rex > Do you have this API route in your project? <@610860696023859210>, yep. As a route handler. `route.ts`.
Siamese
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 šŸ™‚
Cornish RexOP
maybe you should run this command:
npm ls sodium
@Great golden digger wasp.
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. šŸ™
Cornish RexOP
@Siamese.
update-next-app# npm ls sodium 
crossmint-monorepo@ /Users/juliojordan/update-next-app
└── (empty)

update-next-app# echo $?       
1
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
@Cornish Rex Just for debugging purposes
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
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.
Cornish RexOP
@Siamese, interesting. Thx! Give me 30 minutes. I'm joining a meeting right now. I'm sorry for the inconvenience.
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
Cornish RexOP
I hope you have upgraded your nextjs with the following command.
@Siamese, yep. I followed the docs.
Delete files associated with route /api/2023-06-09/checkout/orders/[orderIdentifier]/update-buyer and then build again.
@Siamese, I got the same error but from other path. 😭
TypeError: Cannot read properties of undefined (reading 'sodium')
Build error occurred
Error: Failed to collect page data for /api/2023-06-09/checkout/orders
Siamese
Do you have middlewear in your project?
@Siamese Please Search for "sodium" in your entire codebase (not just in pnpm-lock file)
Siamese
Share the codeblocks where the sodium is appearing
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();
}
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 error
I 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?
Just realized you need to run pnpm store prune to clean pnpm cache
Cornish RexOP
What node version you are using?
@Siamese.
update-next-app# node --version
v20.12.2
Siamese
I think it would be a good idea to downgrade next.js
and wait for things to get stable
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.
Siamese
Is your codebase available on github?
Cornish RexOP
@Siamese, not publicly. Its my company product.
Siamese
Oh No problems. I can take a look in the codebase and try if you are able to share it with me somehow