react-jsonschema-form: Production Builds with Vite and AntD theme not running correctly
Prerequisites
- I have searched the existing issues
- I understand that providing a SSCCE example is tremendously useful to the maintainers.
- I have read the documentation
- Ideally, I’m providing a sample JSFiddle or a shared playground link demonstrating the issue.
What theme are you using?
antd
Version
4.2.2
Current Behavior
We are upgrading a project from Webpack to Vite. Currently in development this all works and loads correctly but we have encountered an error with the production build.
After building a production bundle using Vite & AntD theme, there is a console error Uncaught TypeError: generatePickerExports is not a function.
Expected Behavior
Expect the page to load correctly after a production build
Steps To Reproduce
- Use a base Vite project
npm create vite@latest . --template react-ts npm install @rjsf/core@^4.2.2 @rjsf/antd@^4.2.2- Create base page with form
- Run
npm run devand page loads fine - Run
npm build, which runs successfully - Load browser and see error in the console
Environment
- OS: MacOS 12.3
- Node: v16.16.0
- npm: 8.14.0
- vite: 3.0.0
- typescript: 4.6.4
- react: 18.2.0
- antd: 4.22.1
Anything else?
This looks like it may be cause in the import to override moment.js with day.js in this file https://github.com/rjsf-team/react-jsonschema-form/blob/4049011ea59737232a86c193d96131ce61be85fa/packages/antd/src/components/DatePicker/index.js
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 15 (7 by maintainers)
Commits related to this issue
- Fix #2962 to properly build esm version for antd - Updated `package*.json` to add `@rollup/plugin-replace` - Added a `dts.config.js` file that caused `antd/lib` and `rc-picker/lib` to be replaced with... — committed to heath-freenome/react-jsonschema-form by heath-freenome 2 years ago
- Fix #2962 to properly build esm version for antd - Updated `package*.json` to add `@rollup/plugin-replace` - Added a `dts.config.js` file that caused `antd/lib` and `rc-picker/lib` to be replaced with... — committed to heath-freenome/react-jsonschema-form by heath-freenome 2 years ago
- Fix #2962 to properly build esm version for antd - Updated `package*.json` to add `@rollup/plugin-replace` - Added a `dts.config.js` file that caused `antd/lib` and `rc-picker/lib` to be replaced with... — committed to heath-freenome/react-jsonschema-form by heath-freenome 2 years ago
- Fix #2962 to properly build esm version for antd - Updated `package*.json` to add `@rollup/plugin-replace` - Added a `dts.config.js` file that caused `antd/lib` and `rc-picker/lib` to be replaced with... — committed to heath-freenome/react-jsonschema-form by heath-freenome 2 years ago
- Fix #2962 to properly build esm version for antd - Updated `package*.json` to add `@rollup/plugin-replace` - Added a `dts.config.js` file that caused `antd/lib` and `rc-picker/lib` to be replaced with... — committed to heath-freenome/react-jsonschema-form by heath-freenome 2 years ago
- Fix #2962 to properly build esm version for antd (#3044) - Updated `package*.json` to add `@rollup/plugin-replace` - Added a `dts.config.js` file that caused `antd/lib` and `rc-picker/lib` to be rep... — committed to rjsf-team/react-jsonschema-form by heath-freenome 2 years ago
- Fix #2962 to properly build esm version for antd (#3044) - Updated `package*.json` to add `@rollup/plugin-replace` - Added a `dts.config.js` file that caused `antd/lib` and `rc-picker/lib` to be rep... — committed to heath-freenome/react-jsonschema-form by heath-freenome 2 years ago
For me it worked to add this alias to
vite.config.js:I faced the same issue. The problem is that
antdandrc-pickercomponents are imported fromlibdirectories containing CommonJS modules not compatible with Vite. Vite requires ES modules. Although@rjsf/antd/dist/antd.esm.jsis used in Vite build it contains imports of CommonJS modules fromantdandrc-picker. So in order to fix the issue for Vite you have to import ES modules everywhere across this project. As example,DatePicker/index.jsmentioned above:should be changed to:
As a quick workaround I applied the following patch to
antd.esm.js(version 4.23.0) using patch-package: