antfu-collective / vitesse-webext

⚡️ WebExtension Vite Starter Template
MIT License
2.9k stars 224 forks source link

Uncaught SyntaxError: Cannot use import statement outside a module #86

Closed Gujionsen closed 1 year ago

Gujionsen commented 2 years ago

Hi,

I'm getting the error 'Uncaught SyntaxError: Cannot use import statement outside a module' when importing axios in background.ts and could not find the way to fix it.

I also tried add axios in AutoImport configuration like this: 'axios': [['default', 'axios'], as described in unplugin-auto-import documentation, but without success. In this case axios is just undefined.

Could you please give any tip or example how to solve this problem? Any help would be much appreciated.

fhefh2015 commented 2 years ago

Is this problem solved? Having the same problem. Thanks!

ZengTianShengZ commented 1 year ago

Just load axios under devDependencies,background js compilation uses the tsup tool, here are related documents

https://tsup.egoist.dev/#excluding-all-packages

By default tsup bundles all import-ed modules but dependencies and peerDependencies in your packages.json are always excluded, you can also use --external <module|pkgJson> flag to mark other packages or other special package.json's dependencies and peerDependencies as external.