Chrome扩展程序错误:未定义要求

时间:2016-01-01 10:14:08

标签: javascript require

我的目标是包含一个位于node_modules /中的文件夹。使用Node.js我可以这样做:



Error   3   The type 'System.ComponentModel.Component' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.   H:\Vijay-Workspace\Samples\MySQLSample\MySQLSample\Form1.cs 17  33  MySQLSample
Error   4   The type 'System.Data.IDbConnection' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.    H:\Vijay-Workspace\Samples\MySQLSample\MySQLSample\Form1.cs 17  33  MySQLSample




但是在我的Google Chrome扩展程序中,它无法正常工作,它会引发错误:

  

未定义要求。

2 个答案:

答案 0 :(得分:0)

取决于您是否要在后台页面或内容脚本中使用它,但我假设您正在讨论后台页面。

在清单文件中:

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

在main.js中:

require.config({
    baseUrl: "scripts"
});

require( [ /*...*/ ], function(  /*...*/ ) {
    /*...*/

});

然后在background.html中:

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

答案 1 :(得分:0)

我没有找到在Chrome片段中直接运行节点模块的方法。但是,您可以改为运行节点调试。

  1. npm install -g node-inspector(用于安装节点调试模块)
  2. node-debug app.js(运行节点调试)
  3. 然后,chrome将打开一个调试窗口,您可以使用Here的URL查询自己; 此调试基于Chrome本身的v8调试。