vite-plugin / vite-plugin-dynamic-import

Enhance Vite builtin dynamic import
https://www.npmjs.com/package/vite-plugin-dynamic-import
MIT License
193 stars 11 forks source link

Can not support nested try #27

Closed censujiang closed 2 years ago

censujiang commented 2 years ago

For example

    try {
        const markdown = await import(`./docs${Pathfile}.md`);
        md = markdown;
    } catch (e) {
        try {
            const markdown = await import(`./docs${Pathfile}/README.md`);
            md = markdown;
        } catch (e) {
            status = "404";
        }
    }

It throws the following error when compiling

Identifier '__variableDynamicImportRuntime0__' has already been declared (Note that you need plugins to import files that are not JavaScript)
file: xxxxxxxx/index.vue:107:9
105: 
106: export default _sfc_main// ---- dynamic import runtime functions --S--
107: function __variableDynamicImportRuntime0__(path) {
              ^
108:   switch (path) {
109:     case '../docs/privacy':
caoxiemeihao commented 2 years ago

Oh! Actually this is a BUG 🐞

caoxiemeihao commented 2 years ago

Hey! 👋 When I try to reproduce this BUG 🐞, all works! So, it's confusing. vite-plugin-dynamic-import@1.2.0 is available. It may fix this BUG 🐞