I'm developing a google chrome extension that needs some node modules in order to run. These modules have been downloaded with npm.
Asked
Active
Viewed 2,272 times
2
-
It depends on the context you want to use them in (background script, content script, pop-up, etc.) but you could simply just import them, ex: `import Module from 'path/moduleName'` in most contexts. – Titus Aug 29 '18 at 16:19
-
if i do in this way i receive the the following error: `Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.` The file i want to load is a .tm file – alle.manfredi Aug 29 '18 at 16:36
-
You've probably got the file's path wrong. Also, you may have to set those files as web accessible, here is the documentation for that https://developer.chrome.com/extensions/manifest/web_accessible_resources this all depends on the context. – Titus Aug 29 '18 at 16:42
-
thank you very much but if i type `node_modules/*` within `web_accessible_resources` i receive this error: `Failed to load resource: net::ERR_FILE_NOT_FOUND` – alle.manfredi Aug 29 '18 at 16:54
-
You can't `import` modules in a content script. You can use [scriptTagContext](https://github.com/Rob--W/chrome-api/tree/master/scriptTagContext) library that will allow you to use `require`-type modules. – wOxxOm Aug 29 '18 at 17:19
-
thank you but I didn't understand how to use it in order to load the node modules. – alle.manfredi Aug 30 '18 at 07:34
-
i solved by using this: [chrome-extension-skeleton](https://github.com/salsita/chrome-extension-skeleton) – alle.manfredi Aug 30 '18 at 10:06