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

Posted

技术标签:

【中文标题】Rails 6 webpacker找不到已安装模块的模块【英文标题】:Rails 6 webpacker cannot find module for installed module 【发布时间】:2019-10-30 21:35:08 【问题描述】:

在我的 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"


我在这里做错了什么?

【问题讨论】:

您能检查一下node_modules/push-menu 文件夹是否存在吗? 【参考方案1】:

看起来推送菜单模块坏了:

它定义了一个“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'

【讨论】:

以上是关于Rails 6 webpacker找不到已安装模块的模块的主要内容,如果未能解决你的问题,请参考以下文章

LNMP1.4环境中安装fileinfo插件

Rails 6.1:Webpacker 找不到 application.js

Python 找不到已安装的模块('slackclient')

Ruby-Audio - “找不到指定的模块......”

运行 gulp app:serve rails 时找不到模块“require-dir”错误

节点找不到已安装的模块