Umes Bastola
Umes Bastola

Reputation: 516

Rails 6 webpacker cannot find module for installed module

in my Rails 6 project, i added jQuery pushMenu with

yarn add push-menu

from https://www.npmjs.com/package/push-menu Now i can see this in node-modules folder, as push-menu. however, when i try to import or include from packs, as:

require("push-menu")

i get the following error:

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

my package.json file looks like this

//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"
}
}

What am i doing wrong here?

Upvotes: 15

Views: 3649

Answers (1)

stwienert
stwienert

Reputation: 3642

It looks like the push-menu module is broken:

It defines a "app/index.js" as the main index file:

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

but in the node_modules folder there is no node_modules/app/index.js

Try importing it like this:

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

Upvotes: 1

Related Questions