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
-node_modules
--openbci
--browserify
--...
My app.jsfile installs the server to serve the folderpublic
var express = require('express');
var app = express();
app.use(express.static('public'));
app.listen(myPort);
then I created the following 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 === '.') {
dir = process.cwd()
}
**if (exists(join(dir, 'package.json')) || exists(join(dir, 'node_modules'))) {**
return dir
}
if (prev === dir) {
throw new Error('Could not find module root given file: "' + file
+ '". Do you have a `package.json` file? ')
}
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? :)
source
share