Tuesday, 28 August 2018

Accessing module.exports with a browserified node app

We are trying to Browserify our node app

Sample File (index.js)

module.exports = {
  index: () => 'test',
};

Browserify command

browserify src/index.js > dist/bundle.js --node

If we use a file to require and console

console.log(require('src/index'));   // { index: [Function: index] }
console.log(require('dist/bundle')); // { } 

Our expectation is that bundle.js would export the same as index.js.

Can anyone point us at what we are doing wrong or missing?


Additional Info

~This is not our app, this is a sample to demonstrate the issue

We are currently sending our entire app zipped to AWS Lambda with the entry point src/index.index and the objective is to just send the bundle.js file and be able to to have the entry point bundle.index

bundle.js

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
module.exports = {
    index: () => 'test',
};

},{}]},{},[1]);



from Accessing module.exports with a browserified node app

No comments:

Post a Comment