antfu-collective / vitesse-webext

⚡️ WebExtension Vite Starter Template

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught SyntaxError: Cannot use import statement outside a module

Gujionsen opened this issue · comments

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.

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

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.