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.

【初心者向け】クラスのimport/exportで生じたバグ修正(not defined / outside a module)

Posted at

TypeScriptでexportしようとした時に生じたバグの修正メモ。

ReferenceError: exports is not defined

【処方箋】tsconfig.jsonのmodulesをes6以降にする

config.json
{
   "module": "ESNext or ES6", 
}

exportの書き方が、CommonJSとESmodulesによって違う事によって生じるバグ。
TypeScriptの設定ファイルを修正しましょう。

Uncaught SyntaxError: Cannot use import statement outside a module

【処方箋】HTMLのscriptタグのタイプ属性をmoduleに設定する

index.html
  <script src="test2.js" type="module"></script>

モジュールとして利用する場合は、HTML側での指示が必要です。

【参考】
https://developer.mozilla.org/ja/docs/Web/HTML/Element/script#attr-type

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?