Closed leiyue closed 3 years ago
I am experiencing the same during testing of vite2.
Initial review indicates that rollup's external
is not populated during optimisation of the dependencies in resolveQualifiedDeps
, only during build
(which makes the error incorrect, since it states you need to add it to the build
-config, not the optimizeDeps
-config, which has no such option).
Opening the erroring chunk and adding react
to external
manually fixes it (just search for external.push
and insert it).
Maybe moving the external
-option to the shared options will make it more understandable and makes it possible to use it during optimisation?
Note: this is because @apollo/client
's main entry transitively imports React. Although technically Vite should respect externals during pre-bundling, the actual correct config here is to exclude @apollo/client
from pre-bundling because you obviously do not intend to import it (and if you do, even with React externalized, it will still error because react
is not a valid import specifier in the browser).
The even better fix is to ask Apollo client to fix its default import so that it doesn't transitively import React when it claims to be framework agnostic.
I agree with the "even better" fix, completely missed the transitive react import on the main @apollo/client
package.
Proposed solution works like a charm, thanks for the quick reply!
Maybe this will work with you, Its good alternative for who is having problems with apollo Astrid-Client
⚠️ IMPORTANT ⚠️ Please check the following list before proceeding. If you ignore this issue template, your issue will be directly closed.
Describtion
The Vite configuration file specifies the option
build.rollupOptions.external
setting, but it has no effect.When running the
vite
command, the following error still appears:Reproduction
Please provide a link to a repo that can reproduce the problem you ran into.
A reproduction is required unless you are absolutely sure that the the problem is obvious and the information you provided is enough for us to understand what the problem is. If a report has only vague description (e.g. just a generic error message) and has no reproduction, it will be closed immediately.
vite.config.ts
System Info
vite
version:2.0.0-beta.12
MacOS Big Sur
v15.5.1
pnpm 5.15.0
Logs (Optional if provided reproduction)
vite
orvite build
with the--debug
flag.