swc: common js imports are wrong when strict option is given

ECMAScript® 2018 Language Specification

ecma-262/#sec-imports ecma-262/#sec-exports

Example Code:

// foo.js
const NUM = 1;
export default NUM;

// bar.js
import Foo from './foo.js';
// `Foo` should be eq `1`. not an object ( `{ 'default': 1}` )
console.log(Foo);

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Surprisingly this bug still exists in newer versions. When you set “strict” as true, independently of “noInterop” value, it will cause an error. For example, Express DOES have a default export.

(0 , _express).default is not a function

React does not export anything as default, so I think you should import like import * as React from 'react';

It’s just a babel’s option. It removes __esModule. I agree with you that we should follow ecmascript spec. (That’s why I reopened this issue)