-
-
Notifications
You must be signed in to change notification settings - Fork 335
Description
Bug Report & DX Improvement
When using @rc-component/picker within a pnpm monorepo, the library fails at runtime with the error TypeError: generateConfig.getNow is not a function.
This occurs because the current API design requires consumers to use deep imports to access the necessary generateConfig helpers (e.g., import momentGenerateConfig from 'rc-picker/lib/generate/moment').
These deep imports are not robust and fail to resolve correctly in a strict pnpm environment due to its symlinked node_modules architecture. The bundler cannot find the module, the generateConfig prop becomes undefined, and the component crashes internally.
This issue forces users to enable shamefully-hoist=true in their .npmrc file as a workaround, which negates many of the benefits of using pnpm.
To Reproduce
Set up a pnpm workspace with a host application and a separate library package.
In the library package, import and use an antd DatePicker, which requires passing the generateConfig prop.
Import the required helper via a deep import: import momentGenerateConfig from 'rc-picker/lib/generate/moment';.
Ensure shamefully-hoist is disabled (pnpm's default).
Attempt to run the application. The build or runtime will fail because the deep import cannot be resolved.
Expected behavior
Essential helpers like generateConfig should be part of the library's public API and exportable from the main entry point, eliminating the need for fragile deep imports. This would ensure compatibility with modern, strict package managers like pnpm out of the box.
Proposed Solution & Pull Request
To solve this and improve the developer experience, the generateConfig helpers should be exported from the main index.tsx file.
This allows developers to switch from the brittle deep import:
// Old, fragile way
import momentGenerateConfig from 'rc-picker/lib/generate/moment';
To a robust, top-level import that works with any package manager:
// New, robust way
import { momentGenerateConfig } from '@rc-component/picker';