vite react plugin bundles element tagnames as <tagname> in production mode
See original GitHub issueDescribe the bug
When bundling an app with React + Vite in production mode, Vite bundles all components with the tag name <tagname>
. I would expect that the tag names be preserved when building for production.
The sample app has the following code:
React.createElement(tagName, {}, children)
It looks like tagName
is being converted to "tagName"
(the string) when building. If I change that tagName
variable to helloworld
, then the elements would show up as <helloworld>
instead.
Reproduction
https://github.com/liamdebeasi/vite-production-demo
Steps to reproduce
- Run
npm install
. - In the
test-module
directory, runnpm pack
. - In the root directory, run
npm install ./test-module/test-module-0.0.1.tgz
. - Run
npm run dev
. - Open page and Dev Tools in the browser.
- Inspect the “My Badge” element. Observe that the element tag name is
<app-badge>
. - Run
npm run build
. - Open the built
index.html
file in a browser. If you have Python 3, you can docd dist && python -m http.server
and navigatelocalhost
at the port specified. - Observe that the badge element is output as
<tagname>
.
Other information:
- This app uses the
@vitejs/plugin-react
plugin. - Removing the
useRef
import intest-module/index.esm.js
seems to fix the issue, but I can’t quite figure out why. - This issue does not happen with React + Webpack.
- Packing + installing
test-module
as a dependency is required to reproduce the issue. Importing from./test-module
instead of packing + installing does not reproduce the issue.
System Info
macOS 11.6.1
node 16.11.1
npm 8.0.0
vite 2.7.2
Used Package Manager
npm
Logs
vite:config bundled config file loaded in 131.34ms +0ms
vite:config using resolved config: {
vite:config plugins: [
vite:config 'alias',
vite:config 'vite:react-babel',
vite:config 'vite:react-refresh',
vite:config 'vite:react-jsx',
vite:config 'vite:modulepreload-polyfill',
vite:config 'vite:resolve',
vite:config 'vite:html-inline-script-proxy',
vite:config 'vite:css',
vite:config 'vite:esbuild',
vite:config 'vite:json',
vite:config 'vite:wasm',
vite:config 'vite:worker',
vite:config 'vite:asset',
vite:config 'vite:define',
vite:config 'vite:css-post',
vite:config 'vite:watch-package-data',
vite:config 'vite:build-html',
vite:config 'commonjs',
vite:config 'vite:data-uri',
vite:config 'rollup-plugin-dynamic-import-variables',
vite:config 'vite:asset-import-meta-url',
vite:config 'vite:build-import-analysis',
vite:config 'vite:esbuild-transpile',
vite:config 'vite:reporter',
vite:config 'vite:load-fallback'
vite:config ],
vite:config build: {
vite:config target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
vite:config polyfillModulePreload: true,
vite:config outDir: '/Users/liamdebeasi/Ionic/vite-production-demo/dist',
vite:config assetsDir: 'assets',
vite:config assetsInlineLimit: 4096,
vite:config cssCodeSplit: true,
vite:config cssTarget: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
vite:config sourcemap: false,
vite:config rollupOptions: {
vite:config input: '/Users/liamdebeasi/Ionic/vite-production-demo/index.html'
vite:config },
vite:config minify: 'esbuild',
vite:config terserOptions: {},
vite:config write: true,
vite:config emptyOutDir: null,
vite:config manifest: false,
vite:config lib: false,
vite:config ssr: false,
vite:config ssrManifest: false,
vite:config reportCompressedSize: true,
vite:config chunkSizeWarningLimit: 500,
vite:config watch: null,
vite:config commonjsOptions: { include: [Array], extensions: [Array] },
vite:config dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
vite:config },
vite:config resolve: { dedupe: [ 'react', 'react-dom' ], alias: [ [Object], [Object] ] },
vite:config optimizeDeps: {
vite:config include: [ 'react/jsx-dev-runtime' ],
vite:config esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
vite:config },
vite:config configFile: '/Users/liamdebeasi/Ionic/vite-production-demo/vite.config.ts',
vite:config configFileDependencies: [ 'vite.config.ts' ],
vite:config inlineConfig: {
vite:config root: undefined,
vite:config base: undefined,
vite:config mode: undefined,
vite:config configFile: undefined,
vite:config logLevel: undefined,
vite:config clearScreen: undefined,
vite:config build: {}
vite:config },
vite:config root: '/Users/liamdebeasi/Ionic/vite-production-demo',
vite:config base: '/',
vite:config publicDir: '/Users/liamdebeasi/Ionic/vite-production-demo/public',
vite:config cacheDir: '/Users/liamdebeasi/Ionic/vite-production-demo/node_modules/.vite',
vite:config command: 'build',
vite:config mode: 'production',
vite:config isProduction: true,
vite:config server: { fs: { strict: true, allow: [Array], deny: [Array] } },
vite:config preview: {
vite:config port: undefined,
vite:config strictPort: undefined,
vite:config host: undefined,
vite:config https: undefined,
vite:config open: undefined,
vite:config proxy: undefined,
vite:config cors: undefined
vite:config },
vite:config env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
vite:config assetsInclude: [Function: assetsInclude],
vite:config logger: {
vite:config hasWarned: false,
vite:config info: [Function: info],
vite:config warn: [Function: warn],
vite:config warnOnce: [Function: warnOnce],
vite:config error: [Function: error],
vite:config clearScreen: [Function: clearScreen],
vite:config hasErrorLogged: [Function: hasErrorLogged]
vite:config },
vite:config packageCache: Map(0) { set: [Function (anonymous)] },
vite:config createResolver: [Function: createResolver]
vite:config } +6ms
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Features | Vite
Vite will detect such bare module imports in all served source files and perform the following: Pre-bundle them to improve page loading speed...
Read more >How can I suppress "The tag <some-tag> is unrecognized in ...
I found a potential fix for this issue - if you are using a plugin (and potentially in other circumstances) you can use...
Read more >Tags and their synonyms - Stack Exchange Data Explorer
SourceTagName, ',') as synonyms, t.tagName, e.body as 'Excerpt', w.body as 'WikiBody' from tags t left join Posts e on t.ExcerptPostId = e.
Read more >html-loader - webpack
Then add the plugin to your webpack config. For example: file.js import html from ". ... If the tag name is not specified...
Read more >react-markdown - Bountysource
Vite and React-Markdown don't seem to play well when building in production mode. (vite build) Note: I'm using the react template of vite....
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
@liamdebeasi Using
createElement
named export from react instead ofReact.createElement
also seems to fix the problem in the repo app. I tested this in Ionic v6 by hand modifyingnode_modules/@ionic/react/dist/index.esm.js
and it got the app to render properly in a prod build.I was able to reproduce with vite v2.7.2 + plugin-react v1.1.3. But after updating to vite v2.7.2 + plugin-react v1.3.1, it worked well. Closing as it seeems to be fixed.