Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: _interop_require_wildcard helper missing #7650

Closed
JSerFeng opened this issue Jul 12, 2023 · 3 comments · Fixed by #7661
Closed

Bug: _interop_require_wildcard helper missing #7650

JSerFeng opened this issue Jul 12, 2023 · 3 comments · Fixed by #7661
Labels
Milestone

Comments

@JSerFeng
Copy link
Contributor

Describe the bug

_interop_require_wildcard is missing, if has module configured to commonjs

Input code

const a = require('foo')
console.log(a)
import('other')

Config

{
  "jsc": {
    "target": "es2020",
    "parser": {
      "syntax": "typescript",
    },
  },
  "isModule": "unknown",
  "module": {
    "type": "commonjs"
  },
}

Playground link

https://play.swc.rs/?version=1.3.66&code=H4sIAAAAAAAAA0vOzysuUUhUsFUoSi0szSxK1VBPy89X1%2BRKBkrk56Tq5eSnayRqcmXmFuQXlWio55dkpBYBpQEdbRHiOAAAAA%3D%3D&config=H4sIAAAAAAAAAz2NSwqAMAwF956iZO1CXHoHD1FqED9NSxNREe9u6m%2BT5A3Dy1EYAyM7aMyhpwaxqUfRDMh1VVdQPjzaxJh%2BTwnvJHbLpuwR2aUhymufed0DBm5Dt8yYvYUmCivdEvgPf4%2B1JEsueB9oZHgqzgsyPIPvowAAAA%3D%3D

Expected behavior

_interop_require_wildcard presents

Actual behavior

_interop_require_wildcard is missing

Version

1.3.66

Additional context

No response

@JSerFeng JSerFeng added the C-bug label Jul 12, 2023
@kwonoj
Copy link
Member

kwonoj commented Jul 12, 2023

I'm not really sure this is a bug: you forced input as cjs and use esm import syntax?

@magic-akari
Copy link
Member

Dynamic import() is supported in both CommonJS and ES modules. In CommonJS modules it can be used to load ES modules.

https://nodejs.org/api/esm.html#import-expressions

The key issue is that we should not run any module transformations when compiling from CJS to CJS.
However, swc always considers the input source to be ESM.

Currently, we only have three options for the input source: Module, Script, and Unknown.
We should try to skip the module transformations based on the input source.

@kdy1 kdy1 added this to the Planned milestone Jul 13, 2023
kdy1 pushed a commit that referenced this issue Jul 17, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.70 Jul 18, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Aug 17, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Aug 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

5 participants