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

🐞: `import(node_modules/xxx)` not works #4

Closed annabe1la closed 2 years ago

annabe1la commented 2 years ago

while using dynamicImports , if .ts used 'a: Types', throw an error [vite] Internal server error: Unexpected token

import { ReportHandler } from 'web-vitals';

export const reportWebVitals = (onPerfEntry?: ReportHandler) => {
  if (onPerfEntry && onPerfEntry instanceof Function) {
    import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
      getCLS(onPerfEntry);
      getFID(onPerfEntry);
      getFCP(onPerfEntry);
      getLCP(onPerfEntry);
      getTTFB(onPerfEntry);
    });
  }
};
annabe1la commented 2 years ago

it happens when u use type annotation, when I removed the annotation, the parser error will be gone

caoxiemeihao commented 2 years ago

I've tried to run it in my test, and it looks works normally.


image
image
annabe1la commented 2 years ago

@caoxiemeihao my code https://github.com/annabe1la/vite-plugin-dynamic-import/tree/playground 357041653549663_ pic 357051653549721_ pic

caoxiemeihao commented 2 years ago

This is really a 🐞. I think I can fix it tomorrow! 😄

caoxiemeihao commented 2 years ago

Hey! 👋
This issue was fixed in the vite-plugin-dynamic-import@0.9.6

annabe1la commented 2 years ago

bravo & grazie