The problem was happening because of turbopack.
I removed the turbopack https://github.com/psankar/test-next-js-lib/commit/a09d2b63d288914688483ec317d06d1667dcf2ae after which the import works fine and the code works.
diff --git a/nextjs/package.json b/nextjs/package.json
index adb86a4..bc15fe9 100644
--- a/nextjs/package.json
+++ b/nextjs/package.json
@@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
- "dev": "next dev --turbopack",
+ "dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"