systemjs / systemjs

Dynamic ES module loader
MIT License
12.9k stars 1.09k forks source link

Uncaught TypeError: Cannot read property '_ansicursor' of undefined #938

Closed chauthai closed 8 years ago

chauthai commented 8 years ago

I'm trying to use knex.js to connect to a local SQLite database in a cordova app using system.js. To connect to the database knex.js uses websql wrapper which depends on the sqlite3 package. mapbox/node-sqlite3/issues/512 So far the error points to ansi function of ansi.js.

Stack trace screenshot: screen shot 2015-11-27 at 14 09 21 screen shot 2015-11-27 at 14 10 35

It seems stream is undefined in the system.js enviroment. I've found a similar issue pointing to an error in browserify TooTallNate/ansi.js#21: process.stderr not being defined is a result of browserify

Also this issue in npmlog npm/npmlog#14 points to the core of the problem: The missing polyfill to export stdout and stderr in node-process. Any chances for a working node-process polyfill?

chauthai commented 8 years ago

I've found a polyfill for process.stdout: https://github.com/kumavis/browser-stdout I may just extend it to support process.stderr too.

chauthai commented 8 years ago

I've managed to build a polyfill for process.stderr: https://gist.github.com/chauthai/cb6108b95c3b98bff175 I'm now encountering a problem with fs.existsSync: screen shot 2015-11-27 at 16 39 14

Looks like fs.existsSync has a dependency on the process.binding function and is not that easily polyfillable.

guybedford commented 8 years ago

I assume you are not using jspm here? Are you running this in Node and not the browser at all?

If so you can just set up a node core mapping like:

System.config({
  map: {
  'assert': '@node/assert',
  'buffer': '@node/buffer',
  'child_process': '@node/child_process',
  'cluster': '@node/cluster',
  'console': '@node/console',
  'constants': '@node/constants',
  'crypto': '@node/crypto',
  'dgram': '@node/dgram',
  'dns': '@node/dns',
  'domain': '@node/domain',
  'events': '@node/events',
  'fs': '@node/fs',
  'http': '@node/http',
  'https': '@node/https',
  'module': '@node/module',
  'net': '@node/net',
  'os': '@node/os',
  'path': '@node/path',
  'process': '@node/process',
  'punycode': '@node/punycode',
  'querystring': '@node/querystring',
  'readline': '@node/readline',
  'repl': '@node/repl',
  'stream': '@node/stream',
  'string_decoder': '@node/string_decoder',
  'sys': '@node/sys',
  'timers': '@node/timers',
  'tls': '@node/tls',
  'tty': '@node/tty',
  'url': '@node/url',
  'util': '@node/util',
  'vm': '@node/vm',
  'zlib': '@node/zlib'
  }
});

If you are running the in the browser, then you need the polyfills though.

chauthai commented 8 years ago

Hi,

I'm using jspm and run it in the browser. I've stopped investigating because of the process.binding dependency which leads into a node.js platform specific C implementation.

guybedford commented 8 years ago

Right, yes it doesn't sound like this package will browserify easily.

shaikhather commented 8 years ago

any solution for the "ansi" problem, so far.

Regards,