swc-project / register

Use @swc-node/register instead
Other
86 stars 9 forks source link

bug: When package.json "type" to "commonjs", .mts file should be "esmodule" #25

Closed Tarrowren closed 1 year ago

Tarrowren commented 1 year ago

main.mts


import { hello } from "./hello.mjs";

console.log(hello());


> hello.mts
```ts
export function hello() {
  return "hello";
}
> swc-node main.mts

(node:16280) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
import{hello}from"./hello.mjs";console.log(hello()); 
^^^^^^

SyntaxError: Cannot use import statement outside a module