semantic-ui dropdown menu functionality not working in rails 6

孤人 提交于 2021-02-10 20:40:44

问题


I added semantic-ui gem in gemfile everything is working fine but dropdown menu is not working. I did not find any solution anywhere,
is this an issue in gem to use in rails6?
here is javascript code in application.js file.

require("jquery")
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require("semantic-ui")
require("bootstrap/dist/js/bootstrap")

// Uncomment to copy all static images under ../images to the output folder and reference
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
// or the `imagePath` JavaScript helper below.
//
// const images = require.context('../images', true)
// const imagePath = (name) => images(name, true)
$(document).on('turbolinks:load', function(){
    $('.ui .dropdown').dropdown();
})

I got this error in console in chrome development tool.

Uncaught Error: Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Package exports for '/Users/letsventure/Project/message_me/node_modules/@babel/helper-compilation-targets' do not define a '.' subpath
    at applyExports (internal/modules/cjs/loader.js:485)
    at resolveExports (internal/modules/cjs/loader.js:508)
    at Function.Module._findPath (internal/modules/cjs/loader.js:577)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:879)
    at Function.Module._load (internal/modules/cjs/loader.js:785)
    at Module.require (internal/modules/cjs/loader.js:956)
    at require (Users/letsventure/Project/message_me/node_modules/v8-compile-cache/v8-compile-cache.js:161)
    at Object.<anonymous> (Users/letsventure/Project/message_me/node_modules/@babel/preset-env/lib/debug.js:8)
    at Module._compile (Users/letsventure/Project/message_me/node_modules/v8-compile-cache/v8-compile-cache.js:192)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103)
    at Module.load (internal/modules/cjs/loader.js:914)
    at Function.Module._load (internal/modules/cjs/loader.js:822)
    at Module.require (internal/modules/cjs/loader.js:956)
    at require (Users/letsventure/Project/message_me/node_modules/v8-compile-cache/v8-compile-cache.js:161)
    at Object.<anonymous> (Users/letsventure/Project/message_me/node_modules/@babel/preset-env/lib/index.js:11)
    at Module._compile (Users/letsventure/Project/message_me/node_modules/v8-compile-cache/v8-compile-cache.js:192)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103)
    at Module.load (internal/modules/cjs/loader.js:914)
    at Function.Module._load (internal/modules/cjs/loader.js:822)
    at Module.require (internal/modules/cjs/loader.js:956)
    at require (Users/letsventure/Project/message_me/node_modules/v8-compile-cache/v8-compile-cache.js:161)
    at requireModule (Users/letsventure/Project/message_me/node_modules/@babel/core/lib/config/files/plugins.js:165)
    at loadPreset (Users/letsventure/Project/message_me/node_modules/@babel/core/lib/config/files/plugins.js:83)
    at createDescriptor (Users/letsventure/Project/message_me/node_modules/@babel/core/lib/config/config-descriptors.js:154)
    at Users/letsventure/Project/message_me/node_modules/@babel/core/lib/config/config-descriptors.js:109
    at Array.map (<anonymous>)
    at createDescriptors (Users/letsventure/Project/message_me/node_modules/@babel/core/lib/config/config-descriptors.js:109)
    at createPresetDescriptors (Users/letsventure/Project/message_me/node_modules/@babel/core/lib/config/config-descriptors.js:101)
    at presets (Users/letsventure/Project/message_me/node_modules/@babel/core/lib/config/config-descriptors.js:47)
    at mergeChainOpts (Users/letsventure/Project/message_me/node_modules/@babel/core/lib/config/config-chain.js:320)
    at Object../app/javascript/packs/application.js (bootstrap:83)
    at __webpack_require__ (bootstrap:19)
    at bootstrap:83
    at bootstrap:83

if you want to know more about code used in this project please comment.


回答1:


Follow these steps for Rails 6 to use semantic ui dropdown menu

Add packages with yarn:

yarn add jquery popper.js semantic-ui-sass

In config/webpack/environment.js add the following:

const webpack = require("webpack")
 
environment.plugins.append("Provide", new webpack.ProvidePlugin({
  $: 'jquery',
  jQuery: 'jquery',
  Popper: ['popper.js', 'default']
}))

In app/javascript/packs/application.js add the following:

require("semantic-ui-sass")

In app/javascript/packs/application.js

$(document).on("turbolinks:load", () => $(".ui.dropdown").dropdown());


来源:https://stackoverflow.com/questions/59734369/semantic-ui-dropdown-menu-functionality-not-working-in-rails-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!