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

@petetnt
Copy link

petetnt 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
Copy link
Author

petetnt commented Mar 13, 2016

@cherepanov
Copy link

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

@gamebox
Copy link

gamebox 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
Copy link
Member

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

@gamebox
Copy link

gamebox commented Jul 20, 2016

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

@gamebox
Copy link

gamebox commented Jul 20, 2016

Here you go @TrySound https://github.com/gamebox/react-material-ui-fun

@TrySound
Copy link
Member

Fixed in rollup/rollup-plugin-commonjs#80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants