-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Closed
Labels
feat: deps optimizerEsbuild Dependencies OptimizationEsbuild Dependencies Optimizationp3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Description
Describe the bug
When a dependency is added in optimizeDeps.exclude, it injects __reExport during dependency pre-bundling (link) which removes default property.
Steps to reproduce:
- Copy the project from https://stackblitz.com/edit/vitejs-vite-u5bre3 to a local dev environment since StackBlitz doesn't show
node_modules/directory. - The vite configuration is doing two things:
- Excluding
reactfromoptimizeDeps. - Declaring a plugin that marks
reactimports as external and replaces them with external ESM URLs.
- Excluding
- Start dev server and open the URL. It throws error in browser console.
- Search
node_modules/.vite/depsfor a chunk file that contains// external:react. It has the following code snippet:// external:react var react_exports = {}; import * as react_star from "react"; var init_react = __esm({ "external:react"() { __reExport(react_exports, react_star); } }); __reExportremovesdefaultproperty from react import:var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));- Comment out lines 7-12 (both inclusive) in
src/index.tsx. Refresh the webpage, it loads the UI without error. - Alternatively, comment out
optimizeDepsand plugin implementation from vite config. Refresh the webpage, it loads the UI without error. - Issue:
theming.esm.jsis trying to accessReact.Componentbut it isundefinedbecausereact_exportsdoes not contain"default"property.
Reproduction
https://stackblitz.com/edit/vitejs-vite-u5bre3
System Info
System:
OS: Linux 5.0 undefined
CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 7.17.0 - /usr/local/bin/npm
npmPackages:
@vitejs/plugin-react: ^2.1.0 => 2.1.0
vite: ^3.1.3 => 3.1.3Used Package Manager
npm
Logs
Console Error:
Uncaught TypeError: Cannot read properties of undefined (reading 'Component')
at createThemeProvider (theming.js?v=288fcf31:403:27)
at createTheming (theming.js?v=288fcf31:443:20)
at theming.js?v=288fcf31:447:22
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 vuejs/core 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feat: deps optimizerEsbuild Dependencies OptimizationEsbuild Dependencies Optimizationp3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)