Nodejs Browserify Uncaught TypeError: no function exists

I am new to Browserify and try the following: I created a node server and tried to get a package called "openbci" in the browser.

so I have the following file structure:

Myapp
-...
-public
--app.js
--index.html
--openBCI.js
--...
--javascript
---openBCI
----bundle.js
---...
-node_modules
--openbci
---openBCIBoard.js
--browserify
--...

My app.jsfile installs the server to serve the folderpublic

// app.js
var express = require('express');
var app = express();
app.use(express.static('public'));
app.listen(myPort);

then I created the following openBCI.js

// openBCI.js
var OpenBCIBoard = require('openbci').OpenBCIBoard;
exports.OpenBCIBoard = OpenBCIBoard;

and finally launched a browser command:

$ browserify public/openBCI.js > public/javascript/openBCI/bundle.js

but once called in my index.htmlfile, I got Uncaught TypeError: exists is not a functionin 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, '..')
  }
}

It seems that he could not find the source path for the module. Could you tell me what will change? Or, if I even understood how the browser works? :)

+4
source share
1 answer

, .

  • exists - undefined JavaScript node. , fs.exists - ?

, fs.exists . fs.stat fs.access. , , (), Sync .

  1. , , . browserify-fs, fs . , , IndexedDB, .

, , .

+1

Source: https://habr.com/ru/post/1666938/


All Articles