【问题标题】:Webpacker error when running server for new Rails app为新 Rails 应用程序运行服务器时出现 Webpacker 错误
【发布时间】:2020-07-01 20:09:46
【问题描述】:

刚刚创建了一个全新的 Rails 应用程序并在运行服务器时收到此错误:

Webpacker can't find application.js in /public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
   unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}

这是我的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_output_path: packs
  cache_path: tmp/cache/webpacker
  webpack_compile_output: false

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

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

  extensions:
    - .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
    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

  # Cache manifest.json for performance
  cache_manifest: true

运行./bin/webpack后,建议我通过yarn add -D安装webpack-cli。 执行此操作后,出现以下错误:

Error: Cannot find module 'webpack-cli'
Require stack:
- ../node_modules/webpack/bin/webpack.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1030:15)
    at Function.Module._load (internal/modules/cjs/loader.js:899:27)
    at Module.require (internal/modules/cjs/loader.js:1090:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at ../node_modules/webpack/bin/webpack.js:143:5
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
 '../node_modules/webpack/bin/webpack.js'
  ]

我没有manifest.json - 这不应该是自动创建的吗?

有什么想法吗?

【问题讨论】:

  • 试试 rake webpacker:install
  • 不幸的是仍然遇到同样的错误!
  • 试试 bundle exec bin/webpack-dev-server
  • 请发布您的config/webpacker.yml 文件以及运行./bin/webpack. 的输出
  • @rossta 我已经编辑了我的帖子以包含webpacker.yml./bin/webpack 的输出

标签: javascript ruby ruby-on-rails-6 webpacker


【解决方案1】:

问题来自本地计算机上的节点版本。当您创建 Rails 应用程序时,您可能会弹出如下错误:

The JavaScript app source directory already exists
   apply  /Users/mconiaris/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/webpacker-4.0.7/lib/install/binstubs.rb
  Copying binstubs
       exist    bin
      create    bin/webpack
      create    bin/webpack-dev-server
      append  .gitignore
Installing all JavaScript dependencies [4.0.7]
         run  yarn add @rails/webpacker from "."
yarn add v1.17.3
info No lockfile found.
[1/4] ?  Resolving packages...
warning @rails/webpacker > postcss-preset-env > postcss-color-functional-notation > postcss-values-parser > flatten@1.0.2: I wrote this module a very long time ago; you should use something else.
[2/4] ?  Fetching packages...
error get-caller-file@2.0.5: The engine "node" is incompatible with this module. Expected version "6.* || 8.* || >= 10.*". Got "9.4.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

要解决这个问题,首先确认你的节点版本,确保它不是9.x.x

node -v

再次检查版本。如果是12.10 或更高版本,您应该准备就绪。

开始另一个全新的 Rails 项目,它应该可以正常工作。

祝你好运!

【讨论】:

    猜你喜欢
    • 2019-12-29
    • 2020-04-12
    • 2017-11-07
    • 2012-11-02
    • 2020-10-20
    • 2016-10-03
    • 1970-01-01
    • 1970-01-01
    • 2014-03-13
    相关资源
    最近更新 更多