Skip to content
This repository was archived by the owner on Sep 2, 2023. It is now read-only.
This repository was archived by the owner on Sep 2, 2023. It is now read-only.

import cjs strange behaviour (interop with babel) #480

@shrpne

Description

@shrpne

I have tried to update my library that depends on other cjs libraries.
But I encountered a problem, that import * as foo from 'foo' treats it as
{default: {bar, baz}}
when foo/index.js contains

exports = {bar, baz}

As I know such module representation does not match current implementations, e.g. Babel, which doesn't wrap module content into {default: ...}.

So if I write

import * as foo from 'foo'
foo.bar()

Node will complain "bar is not a function", because foo.default.bar should be used

And if I write

import foo from 'foo'
foo.bar()

Babel will complain "Cannot read property 'bar' of undefined", because default export is undefined, so foo is undefined too

I guess TS it works like Babel here.
I don't understand why module-as-default representation of a module was implemented, I think it is very weird.
So how I should write my library so it can be used with native Node and can be transpiled too?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions