Production Builds with Vite and AntD theme not running correctly
See original GitHub issuePrerequisites
- 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 dev
and 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
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:15 (7 by maintainers)
Top Results From Across the Web
vite breaks in production, but works fine in dev mode. #7335
Some context; This code works perfectly fine in CRA, and vite dev environment. But (for me) it breaks when doing vite build &&...
Read more >How to change antd theme in Vite config? - Stack Overflow
In dark mode, the style of the select component does not work properly. import { getThemeVariables } from 'antd/dist/theme' ... css: { modules ......
Read more >Getting Started - Ant Design
Here is a simple online codesandbox demo of an Ant Design component to show the usage of Ant Design React. CodeSandbox. antd reproduction...
Read more >cannot find module 'antd' or its corresponding type declarations.
Typescript warning "Cannot find module" importing AntDesign components ... npm run build ("build": "tsc && vite build --mode production").
Read more >Setting up a dev environment with React, Vite, and Tailwind
What is Vite? Vite vs. webpack and traditional bundlers. Performance advantages; Cold starting apps; Bundling process; Code splitting. Setting ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For me it worked to add this alias to
vite.config.js
:I faced the same issue. The problem is that
antd
andrc-picker
components are imported fromlib
directories containing CommonJS modules not compatible with Vite. Vite requires ES modules. Although@rjsf/antd/dist/antd.esm.js
is used in Vite build it contains imports of CommonJS modules fromantd
andrc-picker
. So in order to fix the issue for Vite you have to import ES modules everywhere across this project. As example,DatePicker/index.js
mentioned 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: