【发布时间】:2017-02-21 06:01:20
【问题描述】:
我正在尝试使用 require 加载 protobuf js 文件,但在控制台上出现以下异常。
02-21 11:18:06.445 9130-9130/com.p.protoextensiontest I/chromium: [INFO:CONSOLE(5)] "Uncaught Error: Module name "js/proto/data_main_1_pb" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded", source: file:///android_asset/www/js/require.js (5)
"Uncaught Error: Mismatched anonymous define() module: function p(){
这是我的 index.js 代码
var proto = require('js/proto/aaa_bbb_1_pb');
function onCreate(){
console.log("in onCreate");
parseProto();
}
function parseProto(){
var name = proto.person.personName;
}
这是我的 index.html
<head>
<title> Testing proto extension</title>
<script src="js/require.js"></script>
<script src="js/google-protobuf.js"></script>
<script src="js/index.js"></script>
</head>
<body>
<button type="button" onclick="onCreate()"> Create Data</button> <br/>
</body>
我是 javascript 和 node.js 的新手。请提供任何参考。
【问题讨论】:
标签: javascript node.js requirejs node-modules