简体   繁体   English

Application.js 找不到@rails

[英]Application.js can't find @rails

I'm updating a fairly old project to rails 6, and adapt to current "rails ways".我正在将一个相当老的项目更新到 rails 6,并适应当前的“rails 方式”。 And I've just installed webpacker, but I've run into problem I can't seem to find a way to solve.我刚刚安装了 webpacker,但遇到了问题,我似乎找不到解决的方法。

When running the project, I get this error: Uncaught Error: Cannot find module '@rails/ujs'运行项目时,我收到此错误: Uncaught Error: Cannot find module '@rails/ujs'

I've tried to reinstall rails-ujs through yarn, but to no effect.我试图通过纱线重新安装 rails-ujs,但没有效果。

Also I've tried to comment the line require("@rails/ujs").start() from my app/javascript/packs/application.js , and yet I got another error: Uncaught Error: Cannot find module '@rails/activestorage' .此外,我试图从我的app/javascript/packs/application.js 中评论require("@rails/ujs").start() ,但我遇到了另一个错误: Uncaught Error: Cannot find module '@rails/activestorage'

Which leads me to believe that its the global @rails that is not being recognized, however I have no idea where is it set or how to do so.这让我相信它的全局@rails未被识别,但是我不知道它在哪里设置或如何设置。

My questions are: Can I set @rails myself?我的问题是:我可以自己设置@rails吗?

Is there a way to re-generate it?有没有办法重新生成它?

or或者

Is there another configuration I should fix?我应该修复其他配置吗?

It's not @rails which is missing, it's the ujs (and active storage) JavaScript packages which are missing.不是缺少 @rails,而是缺少 ujs(和活动存储)JavaScript 包。

Run yarn install To install them.运行yarn install来安装它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM