Git Product home page Git Product logo

Comments (4)

mjackson avatar mjackson commented on May 4, 2024

I hadn't ever seen it before either but when I looked up how to do module.exports in the TypeScript docs that's how it said it should be done. AFAICT export = is the TypeScript equivalent for ESM export default. In TypeScript, export default is actually a named export called default.

from remix.

mjackson avatar mjackson commented on May 4, 2024

Ya, just confirmed. If I use export default loader I get exports.default = loader in my .js file. But export = loader gives me module.exports = loader in the CommonJS output.

from remix.

kentcdodds avatar kentcdodds commented on May 4, 2024

Any chance the code that requires the loaders could handle this case (kinda like babel's interop require thing):

function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : { default: obj };
}

I do this in babel-plugin-macros: https://github.com/kentcdodds/babel-plugin-macros/blob/3263dbe8f9153090249fc2b8dcc4a5c6d61b6625/src/index.js#L84-L88

function interopRequire(path) {
  const o = require(path)
  return o && o.__esModule && o.default ? o.default : o
}

That works for babel because they set the __esModule property. TypeScript doesn't do this, so it'd probably be better to go with something like this:

function interopRequire(path) {
  const o = require(path)
  return typeof o === 'object' && o.default ? o.default : o
}

I think that would be pretty safe and would allow us to avoid the odd syntax.

from remix.

kentcdodds avatar kentcdodds commented on May 4, 2024

This is no longer relevant

from remix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.