1

I'm trying to run the csv-parse. And it fails with

Uncaught Error: Module name "stream" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded require.js:166
makeError require.js:166
localRequire require.js:1392
requirejs require.js:1737
(anonymous function) index.js?bust=1400069530273:58

The code in node_modules/csv-parse/lib/index.js (not async!):

stream = require('stream');

I try to access the csvparse with this code:

define ['qunit'], () ->
    csvparse = require(['csvparse'])
    QUnit.test "csv namespace", () ->
        QUnit.ok( csvparse?, "csvparse should exists: #{csvparse}" )

In my script for QUnit under Scripts folder I do

requirejs.config({
    baseUrl: '.',
    paths: {
        jquery: '../bower_components/jquery/dist/jquery',
        qunit: '../bower_components/qunit/qunit/qunit',
        csvparse: '../node_modules/csv-parse/lib/index',
        util: '../node_modules/util/util',
        stream: '../node_modules/stream/index'
    },
});

My tree structure is

|--bower_components
|  |--bootstrap
|  |--jquery
|  \--qunit
|--Content
|--node_modules
|  |--bower
|  |--csv-parse
|  |  |--lib
|  |  |--samples
|  |  |--src
|  |  \--test
|  |--grunt
|  |--grunt-contrib-coffee
|  |--grunt-contrib-less
|  |--grunt-contrib-qunit
|  |--grunt-contrib-watch
|  |--requirejs
|  |  \--bin
|  |--stream
|  |  \--node_modules
|  \--util
|     |--node_modules
|     |--support
|     \--test
\--Scripts

So the problem as I see it is that the 'stream' module is not loaded. So how to make it work in the browser (Chromium 35)? Thanks!

Artyom
  • 3,507
  • 2
  • 34
  • 67

1 Answers1

1

You might have better luck using something like browserify since stream is a node core module and the stream module in npm hasn't been updated in a long time and probably lags behind in terms of fixes and updates.

mscdex
  • 104,356
  • 15
  • 192
  • 153
  • Yes, that helped. I've "browserified" the `csv-parse` and it is loaded. Thanks! – Artyom May 15 '14 at 11:30
  • I was too hurry to mark your answer. I got lost again. Now with the Browserify. I load the browserified bundle via requirejs and it does not load this browserified csv-parse module but loads some `function localRequire(deps, callback, errback)` from r.js. So this brings me back as I'm lost again. – Artyom May 15 '14 at 12:20
  • browserify brings its own require(), just like node has. So you'd just do `var csv = require('csv-parse');` like you would in node. – mscdex May 15 '14 at 12:37
  • yeah, but it seems I have to choose only one, ie browserify or r.js. Right? – Artyom May 15 '14 at 12:43
  • Probably, if requirejs has no way to configure their require() function name. – mscdex May 15 '14 at 12:45