LoginSignup
13
16

More than 5 years have passed since last update.

ElectronでjQueryがundefinedになったけど2行で解決した話

Posted at

経緯

テレビ画面のプロトタイプを作るってことで、Electronでサクッと作るのがいいなと思い、jQueryでサクッと作ろうと思ったらいきなりつまづいたので、忘備録。

現象


    <script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="js/script.js"></script>

こんな感じでインポートしたらコンソールにエラー出た

$ is not undefined

Chromeで動くのになんでや。。。
サクッと解決したい!

解決策

サクッと解決2ステップ

  1. npmにjqueryをインストールする

$ npm install jquery --save

  1. jqueryと自分の作ったjavascriptの間にこれを入れる

<script>window.$ = window.jQuery = require('jquery');</script>

これで解決しました。

13
16
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
13
16