Webpacker: Module not found: Error: Can't resolve '@rails/ujs'

Created on 29 Jul 2019  路  5Comments  路  Source: rails/webpacker

Hi,

anyone knows how to solve the problem of Module not found: Error: Can't resolve '@rails/ujs' in Rails6.

image

I also tried to install in npm the : npm i @rails/ujs but still the same error that can't find ujs.

If you need more info, let me know.

Thanks in advance.

Most helpful comment

Hi @jakeNiemiec I already resolved the problem. via adding : Rails: ['@rails/ujs'] in environment.js

Thanks
Cheers!

All 5 comments

In order to help debug, could you please post as much as you can of:

  • ./package.json
  • ./config/webpack/environment.js
  • ./config/webpacker.yml
  • ./app/javascript/packs/application.js
  • the full error message (even the parts you wouldn鈥檛 think is relevant)

鈥攖o a single https://gist.github.com. Please tag me via @jakeNiemiec in a comment and I鈥檒l try to troubleshoot any problems directly in the gist.

Hi @jakeNiemiec I already resolved the problem. via adding : Rails: ['@rails/ujs'] in environment.js

Thanks
Cheers!

yarn add @rails/ujs

@lrjbrual I have the same issue and this is working

environment.plugins.prepend('Provide',
  new webpack.ProvidePlugin({
    $: 'jquery',
    jQuery: 'jquery'
    Rails: '@rails/ujs'
  })
)

But I wonder why this way below is not working:

import Rails from "@rails/ujs"
Rails.start()

why this way below is not working

In what way does it not work? If you use it globally (like in a

Related issues

FrankFang picture FrankFang  路  3Comments

ilrock picture ilrock  路  3Comments

ankitrg picture ankitrg  路  3Comments

suhomozgy-andrey picture suhomozgy-andrey  路  3Comments

Eearslya picture Eearslya  路  3Comments