Since lot of js modules are in npm now a days. I was wondering if there is any way to use them directly in making of a chrome extension.
Asked
Active
Viewed 5,470 times
5
-
The extension must include all of its files in the package. Just add a build step. – wOxxOm Jan 09 '18 at 19:28
-
So does that mean its possible? – Gautham Santhosh Jan 10 '18 at 00:00
-
1Possible duplicate of [Is it possible to require npm modules in a chrome extension ?](https://stackoverflow.com/questions/43684452/is-it-possible-to-require-npm-modules-in-a-chrome-extension) – Jonathan Hult Mar 13 '18 at 16:53
-
I add answer on similar question. Look at [stackoverflow.com/a/74680479/19502363](https://stackoverflow.com/a/74680479/19502363) – Anil kumar Dec 04 '22 at 20:40
1 Answers
6
Yes it is possible to use npm packages but they need to be bundled i.e. included in the extension javascript source. What you need to look into is a module bundler like webpack, rollup to create a bundle for your background scripts and/or content scripts along with the required npm packages. Your manifest should point to your bundled files and it should be working fine.
Here is an example

acesmndr
- 8,137
- 3
- 23
- 28