gpt4 book ai didi

ruby-on-rails - 找不到模块 '@rails/ujs' - Rails 6 Webpack 应用程序

转载 作者:行者123 更新时间:2023-12-05 08:39:27 24 4
gpt4 key购买 nike

我在 Rails 6 应用程序中遇到这些错误,所有 javascript 都无法正常工作:

ERROR in ./app/javascript/packs/application.js
Module not found: Error: Can't resolve '@rails/activestorage' in '/Users/jrsahuquillo/Dropbox/myappname/app/javascript/packs'
@ ./app/javascript/packs/application.js 9:0-31

ERROR in ./app/javascript/packs/application.js
Module not found: Error: Can't resolve '@rails/ujs' in '/Users/jrsahuquillo/Dropbox/myappname/app/javascript/packs'
@ ./app/javascript/packs/application.js 5:0-21

我的 package.json 是:

{
"name": "myappname",
"private": true,
"dependencies": {
"@rails/actioncable": "^6.0.0-alpha",
"@rails/activestorage": "^6.0.2",
"@rails/ujs": "^6.0.2",
"@rails/webpacker": "4.2.0",
"bootstrap": "^4.4.1",
"jquery": "^3.4.1",
"jquery-ui": "^1.12.1",
"jquery-ui-dist": "^1.12.1",
"popper.js": "^1.16.0",
"serialize-javascript": "2.1.2",
"turbolinks": "^5.2.0"
},
"version": "0.1.0",
"devDependencies": {
"webpack-dev-server": "^3.8.0"
},
"optionalDependencies": {
"fsevents": "2.0.0"
}
}

application.js 中:

require("@rails/ujs").start();
require("turbolinks").start();
require("@rails/activestorage").start();
require("channels");
require("bootstrap/dist/js/bootstrap");

app/views/layouts/application.html.erb 中:

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>

它工作正常,但我不知道它何时以及为什么停止工作。有人可以帮助我吗?

最佳答案

抱歉,我已经解决了。之前报错,我安装了yarn autoclean,后来发现在.yarnclean里面是这样的:

# asset directories
docs
doc
website
images
assets

我删除了它,错误消失了。

关于ruby-on-rails - 找不到模块 '@rails/ujs' - Rails 6 Webpack 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59344632/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com