Git Product home page Git Product logo

Comments (8)

tunnckoCore avatar tunnckoCore commented on May 31, 2024 1

Next version should fix this once and forever.

from parse-function.

tunnckoCore avatar tunnckoCore commented on May 31, 2024

Strange... it's export default.. I will check it later today

from parse-function.

tunnckoCore avatar tunnckoCore commented on May 31, 2024

Those are the configs for Rollup.. https://github.com/tunnckoCoreLabs/hela-config-tunnckocore/tree/v0.5.19/config

It creates ...

Minute later: I think I got what's the problem. parse-function does not have pkg.legacy and pkg.unpkg fields which are needed for the legacy-browsers and modern-browsers configs. Hm.

GitHub
A `hela` shareable config (preset of tasks) for @tunnckoCore GitHub organization - tunnckoCoreLabs/hela-config-tunnckocore

from parse-function.

tunnckoCore avatar tunnckoCore commented on May 31, 2024

In anyway... i will release #138 in day or two, for sure. So everything will be simplified in terms of usage and dev workflow / building.

from parse-function.

tunnckoCore avatar tunnckoCore commented on May 31, 2024

Can you give me what's the difference between them? What's exported by both?

from parse-function.

ericmorand avatar ericmorand commented on May 31, 2024

require('parse-function/dist/index.js'); returns the parse function itself.
require('parse-function/dist/index.es.js'); returns an object with a default property.

It means that you can't use require('parse-function) in your code because it will resolve to the function itself when run on the server and to an object with a default key on the browser.

from parse-function.

ericmorand avatar ericmorand commented on May 31, 2024

For what it's worth, here is how I export my modules to provide the same API for both:

index.cjs.js:

class Foo {
}
exports.Foo= Foo;

index.es.js:

export class Foo {
}

Then, using either const {Foo} = require('index.cjs.js'); or const {Foo} = require('index.es.js'); leads to the same result: Foo will contain the class/constructor.

from parse-function.

tunnckoCore avatar tunnckoCore commented on May 31, 2024

Consistency is good thing, yea. But it's totally normal to expect require-ing esm to return an object with default key property.

That's why it's in the module field. Because bundlers will load the module field instead, and so the behaving is the same.

example.js

import parse from 'parse-function'

console.log(parse)

is the function if you use bundlers or running it with node -r esm example.js.

require-ing ESM inside CJS is what happening to do the inconsistencies. And that's hat i didn't liked in Babel 6. They kinda forced users to do require('foo-bar').default because they stopped appending module.exports but only doing them as exports.[name]

from parse-function.

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.