Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deep import problem (Vite 2.0.0-beta.2) #1299

Closed
hmaurer opened this issue Jan 2, 2021 · 2 comments
Closed

Deep import problem (Vite 2.0.0-beta.2) #1299

hmaurer opened this issue Jan 2, 2021 · 2 comments

Comments

@hmaurer
Copy link

hmaurer commented Jan 2, 2021

Preface: this issue describes a bug with the firebase SDK version 7.24.0. This is an outdated version of the SDK (8.x now), but the 8.x version does not work with Vite either (though the issue appears different).

Describe the bug

Firebase's SDK involves deep imports, such as:

import "firebase/auth";

Without further action, they cause an error:

Deep import "firebase/auth" should be avoided because dependency "firebase" has been pre-optimized. Prefer importing directly from the module entry:

So far no problem. The trouble is that adding firebase/auth to optimizeDeps.include does not solve the issue. Strangely enough, for another package I used, rxjs/operators, adding it to optimizeDeps.include did solve the issue.

Reproduction

  1. Start with a fresh Vite 2.0.0-beta.2 react app:
npm init @vitejs/app
cd the-app/
npm i && npm i firebase@7.24.0 --save
  1. Add import "firebase/auth"; to src/App.jsx.

  2. Modify vite.config.js to:

import reactRefresh from '@vitejs/plugin-react-refresh'

/**
 * @type { import('vite').UserConfig }
 */
export default {
  plugins: [reactRefresh()],
  optimizeDeps: {
    include: ["firebase/app"]
  }
}
  1. Run npm run dev

You should observe the following output:

18:52:32 [vite] Internal server error:
  Plugin: vite:imports
  File: /Users/hmaurer/Developer/lab/hello-vite-2/src/App.jsx
  Error: Deep import "firebase/auth" should be avoided because dependency "firebase" has been pre-optimized. Prefer importing directly from the module entry:
  
  import { ... } from "firebase"
  
  If the used import is not exported from the package's main entry and can only be attained via deep import, you can explicitly add the deep import path to "optimizeDeps.include" in vite.config.js.
      at tryNodeResolve (/Users/hmaurer/Developer/lab/hello-vite-2/node_modules/vite/dist/node/chunks/dep-ff3dcb8d.js:48151:15)
      at Context.resolveId (/Users/hmaurer/Developer/lab/hello-vite-2/node_modules/vite/dist/node/chunks/dep-ff3dcb8d.js:48096:28)
      at Object.resolveId (/Users/hmaurer/Developer/lab/hello-vite-2/node_modules/vite/dist/node/chunks/dep-ff3dcb8d.js:60769:53)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at async TransformContext.resolve (/Users/hmaurer/Developer/lab/hello-vite-2/node_modules/vite/dist/node/chunks/dep-ff3dcb8d.js:60574:23)
      at async TransformContext.transform (/Users/hmaurer/Developer/lab/hello-vite-2/node_modules/vite/dist/node/chunks/dep-ff3dcb8d.js:54067:38)
      at async Object.transform (/Users/hmaurer/Developer/lab/hello-vite-2/node_modules/vite/dist/node/chunks/dep-ff3dcb8d.js:60830:30)
      at async transformRequest (/Users/hmaurer/Developer/lab/hello-vite-2/node_modules/vite/dist/node/chunks/dep-ff3dcb8d.js:66858:29)
      at async /Users/hmaurer/Developer/lab/hello-vite-2/node_modules/vite/dist/node/chunks/dep-ff3dcb8d.js:66945:32

System Info

  • vite version: 2.0.0-beta.2
  • Operating System: MacOS Catalina
  • Node version: 12.18.4
@Ttou
Copy link

Ttou commented Jan 3, 2021

@yyx990803 这个问题在 2.0.0-beta3 里依然存在吧,我引入 element-plus/lib/theme-chalk/index.css 还是会报错:

4:34:25 PM [vite] Internal server error:
  Plugin: vite:imports
  File: /home/ttou/Projects/self/vite-demo/src/main.ts
  Error: Deep import "element-plus/lib/theme-chalk/index.css" should be avoided because dependency "element-plus" has been pre-optimized. Prefer importing directly from the module entry:
  
  import { ... } from "element-plus"

@yyx990803
Copy link
Member

@Ttou 25adf1e

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants