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

fix(rollup): CommonJS not supported in transforms #11

Open
JamieMason opened this issue Sep 24, 2019 · 0 comments
Open

fix(rollup): CommonJS not supported in transforms #11

JamieMason opened this issue Sep 24, 2019 · 0 comments

Comments

@JamieMason
Copy link
Owner

Description

Using ES Modules is fine, but require calls are behaving unexpectedly.

  1. Create a file eg /path/to/transform.js:

    const { a } = require('./a');
    
    export default babel => {
      const { types: t } = babel;
      console.log(a());
      return {
        visitor: {
          Program(path) {
            path.traverse({
              enter(path) {
                t.removeComments(path.node);
              }
            });
          }
        }
      };
    };
  2. Create a file eg /path/to/a.js:

    module.exports = {
      a: () => 'AAAA'
    };
  3. Select babelv7 in the Transform Menu

  4. Choose /path/to/transform.js

Expected Output

'use strict';

const a = () => 'AAAA';

var main = babel => {
  const { types: t } = babel;
  console.log(a());
  return {
    visitor: {
      Program(path) {
        path.traverse({
          enter(path) {
            t.removeComments(path.node);
          }
        });
      }
    }
  };
};

module.exports = main;

Actual Output

Cannot find module './a'

rollup.js REPL Examples

  1. This ES Modules example is fine.

  2. This CommonJS example doesn't error like it does in Electron (Electron could be a factor) but it also doesn't bundle in the contents of /path/to/a.js – it leaves the require calls there.

Suggested Solution

https://github.com/rollup/rollup-plugin-node-resolve and/or https://github.com/rollup/rollup-plugin-commonj might possibly be needed.

Help Needed

Ideas welcome, I'm stuck so far after an hour or two working on this.

@JamieMason JamieMason changed the title fix(app): CommonJS not supported in transforms fix(rollup): CommonJS not supported in transforms Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant