在我的Rails 6项目中,我用
添加了jQuery pushMenu添加纱线推送菜单
来自https://www.npmjs.com/package/push-menu 现在,我可以在node-modules文件夹中看到它,为推菜单。但是,当我尝试从包中导入或包含包时,如:
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"
}
}
我在这里做什么错了?
答案 0 :(得分:0)
看起来推送菜单模块坏了:
它定义了一个“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'