PlasmoHQ / plasmo

🧩 The Browser Extension Framework
https://www.plasmo.com
MIT License
10.03k stars 346 forks source link

[BUG] @types/chrome is not working #889

Closed doaortu closed 6 months ago

doaortu commented 6 months ago

What happened?

When I scaffold this project using --with-svelte and then create background.ts, and then installing @types/chrome to add autocomplete to chrome namespace, it simply didn't work (the lsp is saying cannot find name 'chrome' ) I don't know if this only happens in svelte template or it happens in all templates.

I tried workaround stated in this link: https://stackoverflow.com/questions/47075437/cannot-find-namespace-name-chrome

basically I need to add /// <reference types="chrome"/> to the top of background.ts file, and it started to work.

but other chrome extension boilerplate (like crxjs) works out of the box without needing me to do the workaround.

Any pointer to why this happens?

Version

Latest

What OS are you seeing the problem on?

Linux

What browsers are you seeing the problem on?

No response

Relevant log output

No response

(OPTIONAL) Contribution

Code of Conduct

aiktb commented 6 months ago

Have you tried deleting node_modules and re-downloading the dependencies? This doesn't look like a plasmo issue. Or use tsc --noEmit to check if this is just vscode bug.

doaortu commented 6 months ago

I've just tried all of those ( deleting node_modules and redownload, tsc --noEmit ), nothing works.

What works for me is: adding "chrome" to types array in tsconfig.json, something like this:

{
  ... // other 
  "types": ["svelte", "chrome"]
}

Thanks for helping me. I'm closing this since I solved the issue.