LoginSignup
0
0

More than 1 year has passed since last update.

Uncaught ReferenceError: $ is not defined Rails6

Posted at

Rails6で非同期処理がうまくいかなかったので備忘録。

Uncaught ReferenceError: $ is not defined

原因としては

・jQueryがうまく読み込めていなかった。
・Rails6でのjQuery導入ができていなかった

:writing_hand:参考にした記事

導入方法

$ yarn add jquery

config/webpack/environment.js
javascript/packs/application.js
に下記を追加

environment.js
const { environment } = require('@rails/webpacker')

//追加部分 
const webpack = require('webpack')
environment.plugins.prepend('Provide',
  new webpack.ProvidePlugin({
    $: 'jquery/src/jquery',
    jQuery: 'jquery/src/jquery'
  })
)

module.exports = environment

application.js
require("jquery")
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