-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
await import('package') behaves differently in serve vs. build results #5499
Comments
Looks similar to #6112 |
@hemengke1997 #11198 (comment)
This is related to rollup commonjs plugin. // vite.config.js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
build: {
commonjsOptions: {
include: []
}
},
optimizeDeps: {
disabled: false
}
}) But I'm not sure whether it's a bug on Vite or plugin-commonjs.
You could use build dep optimization. I guess you can also workaround this by something like: // @ts-expect-error there's a bug
const res = (_res.__esModule ? _res : _res.default) as typeof _res |
Maybe related: #6632 |
@sapphi-red Thanks bro! I found the docs about this then. |
Duplicate of #2139 |
I can't reproduce the issue anymore. As linked above it might be already fixed the same way as #2139. The dev behaviour now aligns with prod (with the |
Describe the bug
This code:
produces two differently structured objects in
serve
andbuild
code bases.Reproduction
I have this in my code:
When I have Vite running in
serve
mode, the log looks like this:...but when I run
vite build
, logging the imported library results in this:...so the actual Mapbox module is tucked away under
m.default
after building my app. Could this be reworked so that the result would be the same in both scenarios? As a temporary workaround I am now always doing my async imports like this:But I thought I would report this anyways, since it feels like a bug to me. There already is a bug report about this #1168, but it apparently was closed without being resolved and I don't know how to re-open issues...
System Info
System: OS: macOS 11.6 CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz Memory: 496.04 MB / 16.00 GB Shell: 3.3.1 - /usr/local/bin/fish Binaries: Node: 14.18.1 - /usr/local/bin/node Yarn: 1.22.4 - /usr/local/bin/yarn npm: 8.1.1 - /usr/local/bin/npm Browsers: Brave Browser: 90.1.23.73 Chrome: 95.0.4638.69 Chrome Canary: 97.0.4687.2 Firefox: 93.0 Safari: 14.1.2 npmPackages: vite: ^2.6.12 => 2.6.13
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: