1

帮助.. 当我在我的 rails 应用程序上部署到 Heroku 时,我在终端上收到此错误。顺便说一句,我在 Ruby 3.0.3 上使用 Rails 7.0.1

 Compilation failed:
remote:        [webpack-cli] ModuleNotFoundError: Module not found: Error: Can't resolve '@hotwired/stimulus-loading' in '/tmp/build_bc8927d3/app/javascript/controllers'
remote:            at /tmp/build_bc8927d3/node_modules/webpack/lib/Compilation.js:2014:28
remote:            at /tmp/build_bc8927d3/node_modules/webpack/lib/NormalModuleFactory.js:791:13
remote:            at eval (eval at create (/tmp/build_bc8927d3/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
remote:            at /tmp/build_bc8927d3/node_modules/webpack/lib/NormalModuleFactory.js:265:22
remote:            at eval (eval at create (/tmp/build_bc8927d3/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
remote:            at /tmp/build_bc8927d3/node_modules/webpack/lib/NormalModuleFactory.js:427:22
remote:            at /tmp/build_bc8927d3/node_modules/webpack/lib/NormalModuleFactory.js:111:11
remote:            at /tmp/build_bc8927d3/node_modules/webpack/lib/NormalModuleFactory.js:663:25
remote:            at /tmp/build_bc8927d3/node_modules/webpack/lib/NormalModuleFactory.js:848:8
remote:            at /tmp/build_bc8927d3/node_modules/webpack/lib/NormalModuleFactory.js:968:5
remote:        resolve '@hotwired/stimulus-loading' in '/tmp/build_bc8927d3/app/javascript/controllers'
remote:          Parsed request is a module
remote:          using description file: /tmp/build_bc8927d3/package.json (relative path: ./app/javascript/controllers)
remote:            Field 'browser' doesn't contain a valid alias configuration
remote:            resolve as module
remote:              looking for modules in /tmp/build_bc8927d3/app/javascript
remote:                single file module
remote:                  using description file: /tmp/build_bc8927d3/package.json (relative path: ./app/javascript/@hotwired/stimulus-loading)
remote:                    no extension
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_bc8927d3/app/javascript/@hotwired/stimulus-loading doesn't exist
remote:                    .js
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_bc8927d3/app/javascript/@hotwired/stimulus-loading.js doesn't exist
remote:                    .jsx
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_bc8927d3/app/javascript/@hotwired/stimulus-loading.jsx doesn't exist
remote:                    .mjs
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_bc8927d3/app/javascript/@hotwired/stimulus-loading.mjs doesn't exist
remote:                    .ts
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_bc8927d3/app/javascript/@hotwired/stimulus-loading.ts doesn't exist
remote:                    .tsx
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_bc8927d3/app/javascript/@hotwired/stimulus-loading.tsx doesn't exist
remote:                    .coffee
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_bc8927d3/app/javascript/@hotwired/stimulus-loading.coffee doesn't exist
remote:                /tmp/build_bc8927d3/app/javascript/@hotwired/stimulus-loading doesn't exist
remote:              /tmp/build_bc8927d3/app/javascript/controllers/node_modules doesn't exist or is not a directory
remote:              /tmp/build_bc8927d3/app/javascript/node_modules doesn't exist or is not a directory
remote:              /tmp/build_bc8927d3/app/node_modules doesn't exist or is not a directory
remote:              looking for modules in /tmp/build_bc8927d3/node_modules
remote:                single file module
remote:                  using description file: /tmp/build_bc8927d3/package.json (relative path: ./node_modules/@hotwired/stimulus-loading)
remote:                    no extension
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_bc8927d3/node_modules/@hotwired/stimulus-loading doesn't exist
remote:                    .js
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_bc8927d3/node_modules/@hotwired/stimulus-loading.js doesn't exist
remote:                    .jsx
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_bc8927d3/node_modules/@hotwired/stimulus-loading.jsx doesn't exist
remote:                    .mjs
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_bc8927d3/node_modules/@hotwired/stimulus-loading.mjs doesn't exist
remote:                    .ts
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_bc8927d3/node_modules/@hotwired/stimulus-loading.ts doesn't exist
remote:                    .tsx
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_bc8927d3/node_modules/@hotwired/stimulus-loading.tsx doesn't exist
remote:                    .coffee
remote:                      Field 'browser' doesn't contain a valid alias configuration
remote:                      /tmp/build_bc8927d3/node_modules/@hotwired/stimulus-loading.coffee doesn't exist
remote:                /tmp/build_bc8927d3/node_modules/@hotwired/stimulus-loading doesn't exist
remote:              /tmp/node_modules doesn't exist or is not a directory
remote:              /node_modules doesn't exist or is not a directory  

我的gemfile上有这个

gem "stimulus-rails" 

我已经试过了

rails stimulus:install

在我的 App/Javascipt/Controllers/application.js

 import { Application } from "@hotwired/stimulus"

const application = Application.start()

// Configure Stimulus development experience
application.debug = false
window.Stimulus   = application

export { application }

但是每次我在heroku上部署它时仍然遇到相同的错误,该应用程序在本地运行良好。

4

1 回答 1

0

问题已修复..

我试着注释掉

 import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"

来自 App/javascript/controllers/index.js 并且它有效!

PS:这是一个临时修复,但不会解决主要问题

于 2022-02-23T16:44:19.070 回答