0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【TypeScript】set "type": "module" in the package.json or use the .mjs extension.でImportできない時の対応方法

Posted at

概要

変数のエクスポートをすると警告が出た場合の解消方法をまとめる

export const name = "hoge"
ts-node src/sec7.ts
(node:13731) 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)

解消方法

コンパイラする時のモジュールパターンをcommonjsにすることで解消する

CommonJSとは、サーバーサイドなどのウェブブラウザ環境外におけるJavaScriptの各種仕様を定めることを目標としたプロジェクトである

tsconfig.json
{
    "module": "commonjs",
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?