router
router copied to clipboard
The exports file is incorrect when using vite3 SSR with esm and noExternal
Version
4.1.3
Reproduction link
Steps to reproduce
When setting noExternal: ['vue-router'], vite will include vue-router in the SSR bundle, too.
According to current 'exports' config, it will bundle the './dist/vue-router.prod.cjs', which will cause the error.
https://github.com/vuejs/router/blob/df836529db63360f0bf9810ccd4e8911846aef45/packages/router/package.json#L13-L17
What is expected?
Run without error
What is actually happening?
file:///home/projects/vitejs-vite-ov33pc/dist/main.js:1 import require$$0, { createSSRApp } from "vue"; ^^^^^^^^^^ SyntaxError: The requested module 'vue' does not provide an export named 'default'
I think we could remove the production line but I'm not sure if this would affect Nuxt @danielroe
Do we need a production version of the mjs?
We might need one. Users might use vue-router in SSR production env with node esm?
Absolutely, ideally we would have a production ESM version for externalising vue-router. I would imagine that the current mjs build is not suitable for production use because perhaps it imports devtools, etc?
I don't think I can just remove the devtools import because one could still want to have it in production and in node builds (like other renderers). In fact, I think it was a mistake to add the global.__VUE_PROD_DEVTOOLS__ = false to the top of the node version and it will be removed in the future. Similarly, the prod version of CJS removed the devtools but I think we will add it back in the future.
I don't think importing vue-devtools in node should error because vue renderers could exist in node. I think we should keep the behavior of being able to strip off devtools during minification though. Without minification, the imports/require of @vue/devtools-api won't be removed (even though @vue/devtools-api has a sideEffects: false.
I'm still unsure if we need to remove the devtools import/require for node. Ideally, it should be stripped off during minification instead but still allow for it to be included with the build flag mentioned above
@meteorlxy I published a version, let me know if it's all good
@posva It works well now. I have removed the workaround alias :+1: