Tuesday, 15 September 2020

How to concatenate all files in a directory using browserify?

I have a directory with various JavaScript files. I want to create one big file out of them using browserify.

I tried browserify bpmn-viewer/*.js --outfile browserify-output.js, but got the following error:

Error: Parsing file /.../bpmn-viewer/moddle.js: Unexpected token (1:26)
    at Deps.parseDeps (/usr/lib/node_modules/browserify/node_modules/module-deps/index.js:519:15)
    at getDeps (/usr/lib/node_modules/browserify/node_modules/module-deps/index.js:447:44)
    at /usr/lib/node_modules/browserify/node_modules/module-deps/index.js:430:38
    at ConcatStream.<anonymous> (/usr/lib/node_modules/browserify/node_modules/concat-stream/index.js:37:43)
    at ConcatStream.emit (events.js:214:15)
    at finishMaybe (/usr/lib/node_modules/browserify/node_modules/readable-stream/lib/_stream_writable.js:630:14)
    at endWritable (/usr/lib/node_modules/browserify/node_modules/readable-stream/lib/_stream_writable.js:638:3)
    at ConcatStream.Writable.end (/usr/lib/node_modules/browserify/node_modules/readable-stream/lib/_stream_writable.js:594:41)
    at DuplexWrapper.onend (/usr/lib/node_modules/browserify/node_modules/readable-stream/lib/_stream_readable.js:577:10)
    at Object.onceWrapper (events.js:298:28)

How do I need to change my command (browserify bpmn-viewer/*.js --outfile browserify-output.js) in order to get the right result?

Update 1: After changing moddle.js to

module.exports=require(28);

var rts = require('./lib/moddle');

module.exports.types = require('./lib/types');

module.exports.ns = require('./lib/ns');

I am getting a different message:

Error: Parsing file browserify-question/bpmn-viewer/object-refs.js: Unexpected token (1:27)
    at Deps.parseDeps (/usr/lib/node_modules/browserify/node_modules/module-deps/index.js:519:15)
    at getDeps (/usr/lib/node_modules/browserify/node_modules/module-deps/index.js:447:44)
    at /usr/lib/node_modules/browserify/node_modules/module-deps/index.js:430:38
    at ConcatStream.<anonymous> (/usr/lib/node_modules/browserify/node_modules/concat-stream/index.js:37:43)
    at ConcatStream.emit (events.js:214:15)
    at finishMaybe (/usr/lib/node_modules/browserify/node_modules/readable-stream/lib/_stream_writable.js:630:14)
    at endWritable (/usr/lib/node_modules/browserify/node_modules/readable-stream/lib/_stream_writable.js:638:3)
    at ConcatStream.Writable.end (/usr/lib/node_modules/browserify/node_modules/readable-stream/lib/_stream_writable.js:594:41)
    at DuplexWrapper.onend (/usr/lib/node_modules/browserify/node_modules/readable-stream/lib/_stream_readable.js:577:10)
    at Object.onceWrapper (events.js:298:28)

The object-refs.js file looks like this:

module.exports=require(84)./lib/refs');

module.exports.Collection = require('./lib/collection');

Update 2: After modifying object-refs.js to

module.exports=require('./lib/refs');

module.exports.Collection = require('./lib/collection');

I am getting this error:

SyntaxError: Unexpected token (22:0) while parsing /home/[...]/[...]/Development/Repositories/git/browserify-question/bpmn-viewer/jquery.js while parsing file: /home/[...]/[...]/Development/Repositories/git/browserify-question/bpmn-viewer/jquery.js
    at DestroyableTransform.end [as _flush] (/usr/lib/node_modules/browserify/node_modules/insert-module-globals/index.js:114:21)
    at DestroyableTransform.prefinish (/usr/lib/node_modules/browserify/node_modules/readable-stream/lib/_stream_transform.js:138:10)
    at DestroyableTransform.emit (events.js:209:13)
    at prefinish (/usr/lib/node_modules/browserify/node_modules/readable-stream/lib/_stream_writable.js:619:14)
    at finishMaybe (/usr/lib/node_modules/browserify/node_modules/readable-stream/lib/_stream_writable.js:627:5)
    at endWritable (/usr/lib/node_modules/browserify/node_modules/readable-stream/lib/_stream_writable.js:638:3)
    at DestroyableTransform.Writable.end (/usr/lib/node_modules/browserify/node_modules/readable-stream/lib/_stream_writable.js:594:41)
    at DestroyableTransform.onend (/usr/lib/node_modules/browserify/node_modules/readable-stream/lib/_stream_readable.js:577:10)
    at Object.onceWrapper (events.js:298:28)
    at DestroyableTransform.emit (events.js:214:15)

The problematic file is jquery.js. Based on the error message I think the error is somewhere on line 22.

Idea highlights a potential problem on line 19:

Screenshot

Here are the lines 1 through 22 of jquery.js:

module.exports=require('QRCzyp');if ( typeof module === "object" && typeof module.exports === "object" ) {
        // For CommonJS and CommonJS-like environments where a proper window is present,
        // execute the factory and get jQuery
        // For environments that do not inherently posses a window with a document
        // (such as Node.js), expose a jQuery-making factory as module.exports
        // This accentuates the need for the creation of a real window
        // e.g. var jQuery = require("jquery")(window);
        // See ticket #14549 for more info
        module.exports = global.document ?
            factory( global, true ) :
            function( w ) {
                if ( !w.document ) {
                    throw new Error( "jQuery requires a window with a document" );
                }
                return factory( w );
            };
    } else {
        factory( global );
    }

// Pass this if window is not defined yet
}(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {


from How to concatenate all files in a directory using browserify?

No comments:

Post a Comment