Chrome extension error: requirement not defined

My goal is to include the folder located in node_modules /. Using Node.js, I can do:

var example = require('example'); 

But in my Google Chrome extension it does not work, it throws an error:

The requirement is not defined.

+6
source share
2 answers

Depends on whether you want to use it on the original page or in the content of the script, but I assume you are talking about a background page.

In the manifest file:

 "background": { "scripts": [ "scripts/require.js","scripts/main.js"] } 

In main.js:

 require.config({ baseUrl: "scripts" }); require( [ /*...*/ ], function( /*...*/ ) { /*...*/ }); 

and then in background.html:

 <script data-main="scripts/main.js" src="scripts/require.js> 
0
source

I have not found a way to directly run node modules in a Chrome fragment. However, you can run node debugging.

  • npm install -g node-inspector (for installing the node debugging module)
  • node -debug app.js (to start node debugging)

Then chrome will open a debug window, which you can request yourself using the URL http: // localhost: 8080 / debug? Port = 5858 ; And this debugging is based on the v8 debugging of Chrome itself.

0
source

All Articles