Javascript Nodejs Browserify Uncaught TypeError:exists不是函数
我刚开始浏览并尝试以下内容: 我创建了一个节点服务器,并试图在浏览器上运行一个名为“openbci”的包 因此,我有以下文件结构:Javascript Nodejs Browserify Uncaught TypeError:exists不是函数,javascript,node.js,browserify,Javascript,Node.js,Browserify,我刚开始浏览并尝试以下内容: 我创建了一个节点服务器,并试图在浏览器上运行一个名为“openbci”的包 因此,我有以下文件结构: Myapp -... -public --app.js --index.html --openBCI.js --... --javascript ---openBCI ----bundle.js ---... -node_modules --openbci ---openBCIBoard.js --browserify --... myapp.js文件将服务器设置
Myapp
-...
-public
--app.js
--index.html
--openBCI.js
--...
--javascript
---openBCI
----bundle.js
---...
-node_modules
--openbci
---openBCIBoard.js
--browserify
--...
myapp.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;
最后启动了browserify命令:
$ browserify public/openBCI.js > public/javascript/openBCI/bundle.js
但一旦在我的index.html
文件中调用,我得到了一个未捕获的类型错误:exists不是function.getRoot上的函数
:
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是如何工作的?:) 我注意到代码中有一些奇怪的地方
存在
在JavaScript或节点中未定义。它似乎是fs.exists的别名,对吗fs.stat
或fs.access
实现相同的效果。但是请注意,您应该提供回调(最好)或使用这些方法的同步版本