Problem
@gigadrive/commons only has a single root export (. in package.json exports). Importing anything from the package (e.g. formatFileSize) pulls in the entire bundle, which includes Node.js-only code like encrypt/decrypt (using crypto), BufferedReadableStream, and sha256.
This causes a runtime crash in Next.js client components ('use client'):
Class extends value undefined is not a constructor or null
at module evaluation (file-preview-panel.tsx:3:1)
The error happens because Node.js globals (crypto.subtle in certain contexts, stream.Readable) are not available in the browser bundle.
Current workaround
Pure utility functions like formatFileSize have to be duplicated locally in consumer packages instead of being imported from @gigadrive/commons. See: https://github.com/Gigadrive/network/blob/feature/storage-management-ui/apps/console.gigadrive.de/src/components/storage/format-bytes.ts
Proposed fix
Add subpath exports to @gigadrive/commons so that pure/universal utilities can be imported without pulling in Node.js-only code:
{
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./format": {
"types": "./dist/format.d.ts",
"require": "./dist/format.js",
"import": "./dist/format.mjs"
}
}
}
This would allow:
// Works in client components — no Node.js dependencies
import { formatFileSize } from '@gigadrive/commons/format';
Alternatively, consider splitting the package into environment-aware entrypoints (e.g. ./crypto for Node-only, ./format and ./utils for universal code).
Problem
@gigadrive/commonsonly has a single root export (.inpackage.jsonexports). Importing anything from the package (e.g.formatFileSize) pulls in the entire bundle, which includes Node.js-only code likeencrypt/decrypt(usingcrypto),BufferedReadableStream, andsha256.This causes a runtime crash in Next.js client components (
'use client'):The error happens because Node.js globals (
crypto.subtlein certain contexts,stream.Readable) are not available in the browser bundle.Current workaround
Pure utility functions like
formatFileSizehave to be duplicated locally in consumer packages instead of being imported from@gigadrive/commons. See: https://github.com/Gigadrive/network/blob/feature/storage-management-ui/apps/console.gigadrive.de/src/components/storage/format-bytes.tsProposed fix
Add subpath exports to
@gigadrive/commonsso that pure/universal utilities can be imported without pulling in Node.js-only code:{ "exports": { ".": { "types": "./dist/index.d.ts", "require": "./dist/index.js", "import": "./dist/index.mjs" }, "./format": { "types": "./dist/format.d.ts", "require": "./dist/format.js", "import": "./dist/format.mjs" } } }This would allow:
Alternatively, consider splitting the package into environment-aware entrypoints (e.g.
./cryptofor Node-only,./formatand./utilsfor universal code).