8000 Named exports get imported using a default import (which doesn't work) · Issue #215 · lebab/lebab · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Named exports get imported using a default import (which doesn't work) #215
Open
@nachoaIvarez

Description

@nachoaIvarez

Take a look at this scenario

// a.js
exports.x = 'x';
exports.y = 'y';

// b.js
var a = require('./a.js');

console.log(a.x);
console.log(a.y);

// > x
// > y

✅ Works

Gets transpiled to:

// a.js
export var x = 'x';
export var y = 'y';

// b.js
import a from './a';

console.log(a.x);
console.log(a.y);

// > export 'default' (imported as 'a') was not found in './a'

❌ Nope.

In order to solve this you need a manual change, so:

// b.js
import { x, y } from './a';

console.log(x);
console.log(y);

// > x
// > y

✅ There we go. But again, this is a manual change.

Once I solved all those kind of issues, all the rest of safe transforms worked like a charm 👍.

I know, in order to figure out this kind of scenarios, lebab should do a lot of extra heavy lifting and run checks of usage across files. This issue is not a feature request. Just pointing out that commonjs is not that safe, specially when using it through --replace. Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0