Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle is built without errors, but running the bundle results in a variable being undefined #554

Closed
petetnt opened this issue Mar 13, 2016 · 7 comments

Comments

Projects
None yet
4 participants
@petetnt
Copy link

commented Mar 13, 2016

Sorry if this report is a bit vague, but I am trying to build a bundle that's gets passed though various plugins. Bundle is built but running it results on following:

var permuteDomain$1 = permuteDomain$1.permuteDomain;
                                     ^

TypeError: Cannot read property 'permuteDomain' of undefined
    at Object.<anonymous> (D:\foo.js:17718:38)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Function.Module.runMain (module.js:457:10)
    at startup (node.js:138:18)
    at node.js:974:3

The file / module in question is this: https://github.com/SalesforceEng/tough-cookie/blob/master/lib/permuteDomain.js which is used by request in slack-notify.

My rollup function looks like this: I am not entirely sure if this is the correct way to approach this. First time using rollup, but my main goal is to have a standalone bundle that can be ran with Node with #!/usr/bin/env node (so a bundle with my code and node_modules included but without Node built-ins).

            rollup.rollup({
                entry: "foo.js",
                plugins: [
                    nodeResolve({
                        jsnext: true,
                        main: true,
                        extensions: ['.js'],
                        preferBuiltins: true
                    }),
                    json(),
                    commonJS({include: 'node_modules/**'}),
                    babel()
                ]
            }).then(function (bundle) {
                return bundle.write({
                    format: 'cjs',
                    dest: "bar.js",
                    banner: "#!/usr/bin/env node"
                })                      
            }).then(resolve).catch(reject);

Anything I should be looking into or is something definitely wrong here?

@petetnt

This comment has been minimized.

Copy link
Author

commented Mar 13, 2016

@cherepanov

This comment has been minimized.

Copy link

commented Apr 21, 2016

I am new to rollup and faced this issue. Any possible workaround? I am trying to create allinone bundle for nodejs application.

@gamebox

This comment has been minimized.

Copy link

commented Jul 18, 2016

I believe I am seeing a similar error. I am building a React project with ES6 syntax and when I use a certain file from one of my dependencies(Material-UI), I get the following error in the console when I run the successfully built bundle:

bundle.js:31704 Uncaught TypeError: Cannot read property 'MakeSelectable' of undefined

Going to the referenced line, I see something strange:

var MakeSelectable = createCommonjsModule(function (module, exports) {
    'use strict';

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.MakeSelectable = undefined;
....
var MakeSelectable = exports.MakeSelectable = function MakeSelectable(Component) {
 ....
}
exports.default = MakeSelectable;
});

var require$$0$103 = (MakeSelectable$1 && typeof MakeSelectable$1 === 'object' && 'default' in MakeSelectable$1 ? MakeSelectable$1['default'] : MakeSelectable$1);
    var MakeSelectable$1 = MakeSelectable$1.MakeSelectable;

MakeSelectable$1 is the undefined variable. Grepping through the file, all references of that particular variable are all in that last two lines, where it is called solely MakeSelectable elsewhere, particularly when the module is defined. Here's my rollup.config.js

import babel from 'rollup-plugin-babel';
import npm from 'rollup-plugin-node-resolve';
import cjs from 'rollup-plugin-commonjs';
import replace from 'rollup-plugin-replace';

export default {
  entry: 'index.js',
  format: 'iife',
  dest: 'dist/bundle.js', // equivalent to --output
  treeshake: true,
  plugins: [
    babel({
      exclude: 'node_modules/**'
    }),
    npm({
      jsnext: true,
      main: true
    }),
    cjs({
      sourceMaps: false
    }),
    replace({
      'process.env.NODE_ENV': JSON.stringify( 'production' )
    })
  ]
};

And my .babelrc

{
  "presets": ["es2015-rollup", "react"]
}
@TrySound

This comment has been minimized.

Copy link
Member

commented Jul 20, 2016

Hi, @gamebox! Can you create repository with minimal reproducing?

@gamebox

This comment has been minimized.

Copy link

commented Jul 20, 2016

Let me push a commit to this silly little project, and I'll post a link.

@gamebox

This comment has been minimized.

Copy link

commented Jul 20, 2016

@TrySound

This comment has been minimized.

Copy link
Member

commented Jul 22, 2016

@TrySound TrySound closed this Jul 22, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.