Heroku部署错误。找不到模块:错误:无法解析“ ./controllers”

时间:2020-11-07 19:29:26

标签: ruby-on-rails heroku deployment

我基于Rails 6的项目,我使用stimulusjs,webpack 4,mySQL。该站点在本地运行良好,但是在Heroky上部署它时,出现错误。代码如下。我是Rails的初学者,很长一段时间以来都感到沮丧。非常感谢您的帮助。

错误

remote:        I, [2020-11-07T19:38:52.393876 #1770]  INFO -- : Writing /tmp/build_9c36cb8a/public/assets/trunks-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.css.gz
remote:        I, [2020-11-07T19:38:52.394256 #1770]  INFO -- : Writing /tmp/build_9c36cb8a/public/assets/visits-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.css
remote:        I, [2020-11-07T19:38:52.394448 #1770]  INFO -- : Writing /tmp/build_9c36cb8a/public/assets/visits-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.css.gz
remote:        Compiling...
remote:        Compilation failed:
remote:        ModuleNotFoundError: Module not found: Error: Can't resolve './controllers' in '/tmp/build_9c36cb8a/app/javascript/packs'
remote:            at /tmp/build_9c36cb8a/node_modules/webpack/lib/Compilation.js:925:10
remote:            at /tmp/build_9c36cb8a/node_modules/webpack/lib/ContextModuleFactory.js:143:23
remote:            at /tmp/build_9c36cb8a/node_modules/neo-async/async.js:2830:7
remote:            at /tmp/build_9c36cb8a/node_modules/neo-async/async.js:6877:13
remote:            at /tmp/build_9c36cb8a/node_modules/webpack/lib/ContextModuleFactory.js:118:26
remote:            at /tmp/build_9c36cb8a/node_modules/enhanced-resolve/lib/Resolver.js:213:14
remote:            at /tmp/build_9c36cb8a/node_modules/enhanced-resolve/lib/Resolver.js:285:5
remote:            at eval (eval at create (/tmp/build_9c36cb8a/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
remote:            at /tmp/build_9c36cb8a/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:44:7
remote:            at /tmp/build_9c36cb8a/node_modules/enhanced-resolve/lib/Resolver.js:285:5
remote:            at eval (eval at create (/tmp/build_9c36cb8a/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
remote:            at /tmp/build_9c36cb8a/node_modules/enhanced-resolve/lib/Resolver.js:285:5
remote:            at eval (eval at create (/tmp/build_9c36cb8a/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:25:1)
remote:            at /tmp/build_9c36cb8a/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43
remote:            at /tmp/build_9c36cb8a/node_modules/enhanced-resolve/lib/Resolver.js:285:5
remote:            at eval (eval at create (/tmp/build_9c36cb8a/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:14:1)
remote:            at /tmp/build_9c36cb8a/node_modules/enhanced-resolve/lib/Resolver.js:285:5
remote:            at eval (eval at create (/tmp/build_9c36cb8a/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:25:1)
remote:            at /tmp/build_9c36cb8a/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43
remote:            at /tmp/build_9c36cb8a/node_modules/enhanced-resolve/lib/Resolver.js:285:5
remote:            at eval (eval at create (/tmp/build_9c36cb8a/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:14:1)
remote:            at /tmp/build_9c36cb8a/node_modules/enhanced-resolve/lib/Resolver.js:285:5
remote:            at eval (eval at create (/tmp/build_9c36cb8a/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
remote:            at /tmp/build_9c36cb8a/node_modules/enhanced-resolve/lib/DirectoryExistsPlugin.js:27:15
remote:            at /tmp/build_9c36cb8a/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:85:15
remote:            at processTicksAndRejections (internal/process/task_queues.js:79:11)
remote:        resolve './controllers' in '/tmp/build_9c36cb8a/app/javascript/packs'
remote:          using description file: /tmp/build_9c36cb8a/package.json (relative path: ./app/javascript/packs)
remote:            Field 'browser' doesn't contain a valid alias configuration
remote:            using description file: /tmp/build_9c36cb8a/package.json (relative path: ./app/javascript/packs/controllers
remote:              as directory
remote:                /tmp/build_9c36cb8a/app/javascript/packs/controllers doesn't exist
remote:        
remote: 
remote:  !
remote:  !     Precompiling assets failed.

package.json

{
  "name": "chronopuncture",
  "private": true,
  "dependencies": {
    "@rails/actioncable": "^6.0.0",
    "@rails/activestorage": "^6.0.0",
    "@rails/ujs": "^6.0.0",
    "@rails/webpacker": "4.2.2",
    "stimulus": "^1.1.1",
    "turbolinks": "^5.2.0"
  },
  "version": "0.1.0",
  "devDependencies": {
  "webpack-dev-server": "^3.11.0"
  },
 "scripts": {
    "dev": "webpack --mode development",
    "build": "webpack --mode production"
  }
}

database.yml

development:
  adapter: mysql2
  host: 127.0.0.1
  database: chronopuncture
  username: root
  password:

production:
  adapter: mysql2

application.js

require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require("controllers")
import { Application } from "stimulus"
import { definitionsFromContext } from "stimulus/webpack-helpers"

const application = Application.start()
const context = require.context("./controllers", true, /\.js$/)
application.load(definitionsFromContext(context))
// Uncomment to copy all static images under ../images to the output folder and reference
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
// or the `imagePath` JavaScript helper below.
//
// const images = require.context('../images', true)
// const imagePath = (name) => images(name, true)

import "controllers"

0 个答案:

没有答案