swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
31.28k stars 1.23k forks source link

Error: Cannot use import statement outside a module #9753

Open zombieJ opened 5 days ago

zombieJ commented 5 days ago

Describe the bug

PR https://github.com/swc-project/swc/pull/9746 add import of Assumptions but not support in node by default:

fatal - Error: Cannot use import statement outside a module
  import { Assumptions } from "./assumptions";
  ^^^^^^

  SyntaxError: Cannot use import statement outside a module
      at internalCompileFunction (node:internal/vm:76:[18])
      at wrapSafe (node:internal/modules/cjs/loader:1283:20)
      at Module._compile (node:internal/modules/cjs/loader:1328:27)
      at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)

It can be reproduce with bun install:

Input code

No response

Config

No response

Playground link (or link to the minimal reproduction)

https://github.com/ant-design/ant-design/actions/runs/11945315620/job/33297778540

SWC Info output

No response

Expected behavior

Work as prev version.

Actual behavior

No response

Version

0.1.16

Additional context

No response

HomyeeKing commented 5 days ago

it blames to the @swc/types , in my case , the error message is Error: Cannot find module '@swc/types' and @swc/types@0.1.12 works

zombieJ commented 4 days ago

@HomyeeKing thx for notice. Lock to 0.1.12 back to work : )

kdy1 commented 4 days ago

Should be fixed by https://github.com/swc-project/swc/pull/9754