-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
without __esModule property when format esm module cause load module error #3399
Comments
temporary workaround for your case. add a {
resolve: {
alias: {
swiper: 'swiper/swiper.cjs'
}
}
} BTW,is possible to achieve this specifc functionality you proposed somehow like add a extra file and use |
yeah, but it's a temporary solution。the problem may be appear frequently |
export default defineConfig({
plugins: [reactRefresh()],
resolve: {
alias: {
swiper: join(__dirname, 'src/swiper'),
'@swiper': join(__dirname, 'node_modules/swiper/swiper.esm')
}
}
}) // src/swiper.js
export * from '@swiper'
export { default } from '@swiper'
export const __esModule = true clean the vite prebundle cache and rebuild. This would work. I think it's a issue of esbuild rather than vite's.😄 |
yeah, i also think that. in the final analysis,the problem is es module and commonjs module are not compatible. |
This causes latest |
I'm also having this issue with |
@antfu @underfin @Shinigami92 @patak-js please see see, the issue occurs many times in different project. for example, use element-ui with vue2.0 and vite |
Does this also happen with Vite |
@Shinigami92 it use the newest vite 2.3.4,although i think it's esbuild problem |
Ok so please downgrade and try it out. Then write me feedback. |
@Shinigami92 vite@2.2.4 will not occur the problem. but we want to use the newest vite.maybe you can push esbuild fix the problem |
Hi, |
This issue has been locked since it has been closed for more than 14 days. If you have found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Vite version. If you have any other comments you should join the chat at Vite Land or create a new discussion. |
Describe the bug
when the thirdparty module is esm format, esbuild manage it without add
__esModule
property. but webpack will add__esModule
property.for examle, the source code is
After esbuild format ,will output
without
__esModule
property.it will be cause an error. if a module build by webpack, the source code as below
after webpack build , output code will add helper function
__importDefault
but because of
__esModule
is undefined,__importDefault
function will add default property once again cause the return value__importDefault(require("swiper")).default
is not the current object will be errorReproduction
https://github.com/zhangyuang/vite-react-swiper-error
System Info
vite/2.3.2 darwin-x64 node-v12.18.3
additional
when i add
__esModule
property in source code manually, it can be executed succeed likeIn this case,maybe vite can add
__esModule
in esbuild plugin . for exampleThe text was updated successfully, but these errors were encountered: