I tried so but I have a 'require is not defined' error. I can't find information about that, can someone enlighten the noob in me please?
相关问题
- Failed at the electron@1.8.2 postinstall script
- Webpack getting started, import error
- No member named ForceSet
- How does same-domain policy apply to background sc
- AWS Elastic BeanStalk nodejs Deployment error
相关文章
- @angular-cli install fails with deprecated request
- Create React App not installing, showing an error
- Progressive web app(PWA) vs Electron vs Browser ex
- new field false in Package.json
- npm : Postinstall not running in docker
- Babel CLI is extremely slow
- Docker and npm - gyp ERR! not ok
- Is there an npm module to modify a pdf file in nod
It's not possible to require node modules directly within a chrome extension. However, it is possible to bundle node applications and packages into the browser for use with your extensions. See here for more: Is it possible to develop Google Chrome extensions using node.js?
It's possible, but you have to be careful. Trying to require() a package means that node will try to locate its files in your file system. A chrome extension only has access to the files you declare in the manifest, not your filesystem.
To get around this, use a module bundler like Webpack, which will generate a single javascript file containing all code for all packages included through require(). You will have to generate a separate module for each component of your chrome extension (e.g. one for the background page, one for content scripts, one for the popup) and declare each generated module in your manifest.
To avoid trying to setup your build system to make using require() possible, I suggest starting with a boilerplate project. You can check out my extension to see how I do it.