Rails 6 webpacker找不到已安装模块的模块

yv5phkfx  于 2022-11-13  发布在  Webpack
关注(0)|答案(1)|浏览(197)

在我的Rails 6项目中,我添加了jQuery pushMenu,
Yarn添加按钮菜单
https://www.npmjs.com/package/push-menu现在,我可以看到这在节点模块文件夹,作为推菜单。然而,当我试图导入或包括从包,如:

require("push-menu")

我得到以下错误:

Uncaught Error: Cannot find module 'push-menu'
at webpackMissingModule (application.js:12)
at Module../app/javascript/packs/application.js (application.js:12)
at __webpack_require__ (bootstrap:19)
at bootstrap:83
at bootstrap:83

我的package.json文件看起来像这样

//package.json file
{
"name": "example_setup",
"private": true,
"dependencies": {
"@rails/actioncable": "^6.0.0-alpha",
"@rails/activestorage": "^6.0.0-alpha",
"@rails/ujs": "^6.0.0-alpha",
"@rails/webpacker": "^4.0.7",
"jquery": "^3.4.1",
"push-menu": "^2.0.8",
"select2": "^4.0.7",
"turbolinks": "^5.2.0"
},
"version": "0.1.0",
"devDependencies": {
"webpack-dev-server": "^3.7.1"
}
}

我做错了什么?

ui7jx7zq

ui7jx7zq1#

看起来,按钮菜单模块损坏:
它定义了一个“app/index.js”作为主索引文件:

{
  "name": "push-menu",
  "version": "2.0.8",
  ...
  "main": "app/index.js",
}

但在node_modules文件夹中没有node_modules/app/index.js
尝试按如下方式导入:

import from 'push-menu/src/js/jquery.pushMenu'

相关问题