question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

To my understanding this will load CJS files and have named property access on them? There is ongoing discussion if this is going to be implemented or not. I am hesitant to encourage named properties working. In all proposed interopoperability scenarios however, there is a default export that maps directly to module.exports. Something to bear in mind, and perhaps remove named imports until interop is ironed out.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Jessidhiacommented, Dec 8, 2016

@bmeck How does something like this sound?

function _specInteropRequireWildcard(obj) {
  if (obj && obj.__esModule) {
    return obj;
  } else {
    var newObj = Object.create
      ? Object.create(null, {
        default: {
          value: obj,
          writable: true,
          enumerable: true
        },
        __esModule: {
          value: true
        }
      })
      : {
        default: obj,
        __esModule: true
      };
    if (typeof Symbol !== "undefined" && Symbol.toStringTag) {
      Object.defineProperty(newObj, Symbol.toStringTag, { value: "Module" });
    }
    return (Object.freeze || Object)(newObj);
  }
}

I’ve been discussing with @loganfsmyth on slack about implementing a possible spec: true version of the transform that could use that improved helper, as well as more spec compliant exports (live binding, immutable module record).

2reactions
bmeckcommented, Dec 7, 2016

I bring this up because, whew boy are we in enough of the weeds due to incompatibilities of existing CJS interop w/ babel and ESM

Read more comments on GitHub >

github_iconTop Results From Across the Web

Modules & CJS interop - Learn TypeScript w/ Mike North
ES Module imports and exports; CommonJS Interop; Importing non-TS things. The JS ecosystem was without an “official” module specification until 2015, ...
Read more >
johnloy/esm-commonjs-interop-manual - GitHub
Interop between ECMAScript modules, aka ES modules, aka ESM, aka JavaScript modules, and CommonJS, aka CJS, modules is a complicated and confusing matter ......
Read more >
swc-plugin-node-cjs-interop - npm
An SWC plugin to fix the default import interoperability issue in Node.js. Latest version: 0.1.1, last published: 5 months ago.
Read more >
node-cjs-interop - npm Package Health Analysis - Snyk
Learn more about node-cjs-interop: package health score, popularity, security, maintenance, versions and more.
Read more >
ESM-CJS interop test - GitHub Pages
node import x import import * as x; x.default import * as x; i... default‑export default‑export‑runtime default‑export‑esModule default‑export‑esModule‑esm‑reexport syntax error undefined
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found