Javascript Nodejs Browserify Uncaught TypeError:exists不是函数

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文件将服务器设置

我刚开始浏览并尝试以下内容: 我创建了一个节点服务器,并试图在浏览器上运行一个名为“openbci”的包

因此,我有以下文件结构:

Myapp
-...
-public
--app.js
--index.html
--openBCI.js
--...
--javascript
---openBCI
----bundle.js
---...
-node_modules
--openbci
---openBCIBoard.js
--browserify
--...
my
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;
最后启动了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.exists。根据文档,您可以使用
    fs.stat
    fs.access
    实现相同的效果。但是请注意,您应该提供回调(最好)或使用这些方法的同步版本

  • 如果您试图在浏览器中使用文件系统工具,您将遇到问题,因为您试图从浏览器访问服务器的文件系统。有一个插件,它在浏览器中为您提供了一个与fs等效的插件。但是,这似乎是访问浏览器的本地IndexedDB,而不是服务器上的存储
  • 我建议在服务器上运行依赖于服务器端文件的代码,而不是在浏览器中运行