rails webpacker错误:ModuleNotFoundError:未找到模块:错误:无法解析“ / home / deploy / clotho / app / javascript / packs”中的“ logo.svg”

问题描述

我在生产服务器(Ubuntu服务器)上运行rails webpacker:compile时出错。之前一切正常,在我的本地计算机(OSX)上一切正常

  • 我的rails版本: 5.2.4.3
  • 我的红宝石版本- 2.6.6
  • 我的werpacker版本- gem'webpacker','〜> 5.1','> = 5.1.1'

但是:

ModuleNotFoundError: Module not found: Error: Can't resolve 'logo.svg' in '/home/deploy/clotho/app/javascript/packs'
    at /home/deploy/clotho/node_modules/webpack/lib/Compilation.js:925:10
    at /home/deploy/clotho/node_modules/webpack/lib/NormalModuleFactory.js:401:22
    at /home/deploy/clotho/node_modules/webpack/lib/NormalModuleFactory.js:130:21
    at /home/deploy/clotho/node_modules/webpack/lib/NormalModuleFactory.js:224:22
    at /home/deploy/clotho/node_modules/neo-async/async.js:2830:7
    at /home/deploy/clotho/node_modules/neo-async/async.js:6877:13
    at /home/deploy/clotho/node_modules/webpack/lib/NormalModuleFactory.js:214:25
    at /home/deploy/clotho/node_modules/enhanced-resolve/lib/Resolver.js:213:14
    at /home/deploy/clotho/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/deploy/clotho/node_modules/tapable/lib/HookCodeFactory.js:33:10),<anonymous>:13:1)
    at /home/deploy/clotho/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:44:7
    at /home/deploy/clotho/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/deploy/clotho/node_modules/tapable/lib/HookCodeFactory.js:33:10),<anonymous>:13:1)
    at /home/deploy/clotho/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/deploy/clotho/node_modules/tapable/lib/HookCodeFactory.js:33:10),<anonymous>:25:1)
    at /home/deploy/clotho/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43
    at /home/deploy/clotho/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/deploy/clotho/node_modules/tapable/lib/HookCodeFactory.js:33:10),<anonymous>:26:1)
    at /home/deploy/clotho/node_modules/enhanced-resolve/lib/ModuleKindPlugin.js:30:40
    at /home/deploy/clotho/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/deploy/clotho/node_modules/tapable/lib/HookCodeFactory.js:33:10),<anonymous>:14:1)
    at /home/deploy/clotho/node_modules/enhanced-resolve/lib/forEachBail.js:30:14
    at /home/deploy/clotho/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/deploy/clotho/node_modules/tapable/lib/HookCodeFactory.js:33:10),<anonymous>:14:1)
    at /home/deploy/clotho/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/deploy/clotho/node_modules/tapable/lib/HookCodeFactory.js:33:10),<anonymous>:25:1)
resolve 'logo.svg' in '/home/deploy/clotho/app/javascript/packs'
  Parsed request is a module
  using description file: /home/deploy/clotho/package.json (relative path: ./app/javascript/packs)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in /home/deploy/clotho/app/javascript
        using description file: /home/deploy/clotho/package.json (relative path: ./app/javascript)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /home/deploy/clotho/package.json (relative path: ./app/javascript/logo.svg)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/app/javascript/logo.svg doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/app/javascript/logo.svg.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/app/javascript/logo.svg.js doesn't exist
            .sass
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/app/javascript/logo.svg.sass doesn't exist
            .scss
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/app/javascript/logo.svg.scss doesn't exist
            .css
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/app/javascript/logo.svg.css doesn't exist
            .module.sass
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/app/javascript/logo.svg.module.sass doesn't exist
            .module.scss
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/app/javascript/logo.svg.module.scss doesn't exist
            .module.css
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/app/javascript/logo.svg.module.css doesn't exist
            .png
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/app/javascript/logo.svg.png doesn't exist
            .svg
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/app/javascript/logo.svg.svg doesn't exist
            .gif
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/app/javascript/logo.svg.gif doesn't exist
            .jpeg
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/app/javascript/logo.svg.jpeg doesn't exist
            .jpg
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/app/javascript/logo.svg.jpg doesn't exist
            as directory
              /home/deploy/clotho/app/javascript/logo.svg doesn't exist
      /home/deploy/clotho/app/javascript/packs/node_modules doesn't exist or is not a directory
      /home/deploy/clotho/app/javascript/node_modules doesn't exist or is not a directory
      /home/deploy/clotho/app/node_modules doesn't exist or is not a directory
      /home/deploy/node_modules doesn't exist or is not a directory
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /home/deploy/clotho/node_modules
        using description file: /home/deploy/clotho/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /home/deploy/clotho/package.json (relative path: ./node_modules/logo.svg)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/node_modules/logo.svg doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/node_modules/logo.svg.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/node_modules/logo.svg.js doesn't exist
            .sass
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/node_modules/logo.svg.sass doesn't exist
            .scss
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/node_modules/logo.svg.scss doesn't exist
            .css
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/node_modules/logo.svg.css doesn't exist
            .module.sass
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/node_modules/logo.svg.module.sass doesn't exist
            .module.scss
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/node_modules/logo.svg.module.scss doesn't exist
            .module.css
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/node_modules/logo.svg.module.css doesn't exist
            .png
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/node_modules/logo.svg.png doesn't exist
            .svg
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/node_modules/logo.svg.svg doesn't exist
            .gif
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/node_modules/logo.svg.gif doesn't exist
            .jpeg
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/node_modules/logo.svg.jpeg doesn't exist
            .jpg
              Field 'browser' doesn't contain a valid alias configuration
              /home/deploy/clotho/node_modules/logo.svg.jpg doesn't exist
            as directory
              /home/deploy/clotho/node_modules/logo.svg doesn't exist

这是我的 webpacker.yml 文件:

# Note: You must restart bin/webpack-dev-server for changes to take effect

default: &default
  source_path: app/javascript
  source_entry_path: packs
  public_root_path: public
  public_output_path: packs
  cache_path: tmp/cache/webpacker
  webpack_compile_output: true

  # Additional paths webpack should lookup modules
  # ['app/assets','engine/foo/app/assets']
  resolved_paths: ['app/javascript/images','app/javascript/fonts']

  # Reload manifest.json on all requests so we reload latest compiled packs
  cache_manifest: false

  # Extract and emit a css file
  extract_css: true

  static_assets_extensions:
    - .jpg
    - .jpeg
    - .png
    - .gif
    - .tiff
    - .ico
    - .svg
    - .eot
    - .otf
    - .ttf
    - .woff
    - .woff2

  extensions:
    - .mjs
    - .js
    - .sass
    - .scss
    - .css
    - .module.sass
    - .module.scss
    - .module.css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg

development:
  <<: *default
  compile: true

  # Reference: https://webpack.js.org/configuration/dev-server/
  dev_server:
    https: false
    host: localhost
    port: 3035
    public: localhost:3035
    hmr: false
    # Inline should be set to true if using HMR
    inline: true
    overlay: true
    compress: true
    disable_host_check: true
    use_local_ip: false
    quiet: false
    pretty: false
    headers:
      'Access-Control-Allow-Origin': '*'
    watch_options:
      ignored: '**/node_modules/**'


test:
  <<: *default
  compile: true

  # Compile test packs to a separate directory
  public_output_path: packs-test

production:
  <<: *default

  # Production depends on precompilation of packs prior to booting for performance.
  compile: false

  # Extract and emit a css file
  extract_css: true

  # Cache manifest.json for performance
  cache_manifest: true

这是我的 webpack / development.js 文件:

process.env.NODE_ENV = process.env.NODE_ENV || 'development'

const environment = require('./environment')

module.exports = environment.toWebpackConfig()

这是我的 webpack / production.js 文件

process.env.NODE_ENV = process.env.NODE_ENV || 'production'

const environment = require('./environment')

module.exports = environment.toWebpackConfig()

这是我的 webpack / environment.js 文件:

const { environment } = require('@rails/webpacker')

module.exports = environment

这是我的 app / javascript / packs / application.js 文件:

import "controllers"
const images = require.context('../images',true)
const fonts = require.context('../fonts',true)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)