LoginSignup
1
0

More than 1 year has passed since last update.

javaScriptでimport/exportするにはサーバーを立ち上げる必要があるなんて知らなかった話

Posted at

ことのはじめ

以前にゲームの設計をして別のクラスを呼び出そうとした。
progateとかでjavaScriptで別のクラスを読み込むにはimport/exportを使えば良いと習ったのでその通りにしたがUnexpected token 'export'とエラーを吐かれた。

そもそものjavaScriptの仕様

タイトルにもあるように、javaScriptでimport/exportをするには

  • ローカルサーバーとかでもいいからサーバーを立ててそこにjavaScriptファイルを置く
  • import/exportするファイルはHTMLで<script src="jsファイルのurl" type="module"></script>と書く必要がある

私がとった方法

参考にしたサイトではvscodeのlive serverを使っていたが
私はxamppを使ってサーバーを立てた

参考

1
0
1

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
1
0