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

CJS->ESM interop issues #5459

Open
devongovett opened this issue Dec 11, 2020 · 3 comments
Open

CJS->ESM interop issues #5459

devongovett opened this issue Dec 11, 2020 · 3 comments

Comments

@devongovett
Copy link
Member

🐛 bug report

While working on #4366 I found a few CJS->ESM interop issues with the existing scope hoisting transformer and namespace imports. For now, I've followed them in the non-scope hoisting modules transformer, but we should do a full sweep and compare our output with Babel and Node.

  1. Non-object exports
import * as n from './class';

// class.js
module.exports = class {}
  • babel: {default: class {}}
  • node: {default: class {}}
  • parcel: class {}
  1. Object exports
import * as n from './object.js';

// object.js
module.exports = {
  foo: 2,
  default: 3
};
  • babel: {foo: 2, default: {foo: 2, default: 3}}
  • node: {default: {foo: 2, default: 3}}
  • parcel: {foo: 2, default: 3}

There are probably more cases too. See https://sokra.github.io/interop-test/.

@mischnic
Copy link
Member

mischnic commented Dec 17, 2020

I just ran into a case where

import Thing from "...";
Thing.default

worked in Node but in Parcel it was

import Thing from "...";
Thing

(importing a CJS file that sets __esModule to true and does exports.default = plugin;)


Related issue: evanw/esbuild#532

@mischnic
Copy link
Member

mischnic commented Jan 28, 2021

Another case is dynamic imports:

import("./b.js").then(console.log);

// b.js
module.exports = function f() {};

Node: [Module] { default: [Function: f] }

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

2 participants