4
我是新来Browserify和尝试以下操作: 我创建了一个节点服务器,并试图获得一个所谓的“openbci”在浏览器中运行包。的NodeJS Browserify遗漏的类型错误:存在不是一个函数
所以我有以下文件结构:
Myapp
-...
-public
--app.js
--index.html
--openBCI.js
--...
--javascript
---openBCI
----bundle.js
---...
-node_modules
--openbci
---openBCIBoard.js
--browserify
--...
我app.js
文件设置服务器,以服务public
文件夹
// app.js
var express = require('express');
var app = express();
app.use(express.static('public'));
app.listen(myPort);
然后我创建了以下openBCI.js
// openBCI.js
var OpenBCIBoard = require('openbci').OpenBCIBoard;
exports.OpenBCIBoard = OpenBCIBoard;
终于推出了browserif Y命令:
$ browserify public/openBCI.js > public/javascript/openBCI/bundle.js
但一旦叫我index.html
文件,我在Function.getRoot有一个Uncaught TypeError: exists is not a function
:
exports.getRoot = function getRoot (file) {
var dir = dirname(file)
, prev
while (true) {
if (dir === '.') {
// Avoids an infinite loop in rare cases, like the REPL
dir = process.cwd()
}
**if (exists(join(dir, 'package.json')) || exists(join(dir, 'node_modules'))) {**
// Found the 'package.json' file or 'node_modules' dir; we're done
return dir
}
if (prev === dir) {
// Got to the top
throw new Error('Could not find module root given file: "' + file
+ '". Do you have a `package.json` file? ')
}
// Try the parent dir next
prev = dir
dir = join(dir, '..')
}
}
看来,它无法找到该模块的原始路径。 你能告诉我什么改变?或者,如果我完全理解browserify是如何工作的? :)