首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ActionController::RoutingError (没有路由匹配[GET]“/packs/js/application.js”)

ActionController::RoutingError (没有路由匹配[GET]“/packs/js/application.js”)
EN

Stack Overflow用户
提问于 2021-06-26 16:53:18
回答 1查看 1.2K关注 0票数 3

我已经用docker安装了rails 6,我的webpacker似乎正在编译资产,但是当我访问我的页面时,它提供了404。

代码语言:javascript
运行
复制
ActionController::RoutingError (No route matches [GET] "/packs/js/application-6527e9c4b100bc10bc71.js")
代码语言:javascript
运行
复制
app         | The Gemfile's dependencies are satisfied
webpack     | ℹ 「wds」: Project is running at http://localhost:3035/
webpack     | ℹ 「wds」: webpack output is served from /packs/
webpack     | ℹ 「wds」: Content not from webpack is served from /app/public/packs
webpack     | ℹ 「wds」: 404s will fallback to /index.html
app         | => Booting Puma
app         | => Rails 6.1.4 application starting in development
app         | => Run `bin/rails server --help` for more startup options
app         | Puma starting in single mode...
app         | * Puma version: 5.3.2 (ruby 3.0.1-p64) ("Sweetnighter")
app         | *  Min threads: 5
app         | *  Max threads: 5
app         | *  Environment: development
app         | *          PID: 10
app         | * Listening on http://0.0.0.0:3000
app         | Use Ctrl-C to stop
webpack     | ℹ 「wdm」: Hash: 81036c4ee13c6e27e31a
webpack     | Version: webpack 4.46.0
webpack     | Time: 931ms
webpack     | Built at: 06/26/2021 4:38:56 PM
webpack     |                                           Asset       Size            Chunks                         Chunk Names
webpack     |          js/application-6527e9c4b100bc10bc71.js   1.76 MiB       application  [emitted] [immutable]  application
webpack     |      js/application-6527e9c4b100bc10bc71.js.map   2.01 MiB       application  [emitted] [dev]        application
webpack     |     js/server_rendering-13527221e10c2e65c45f.js   1.64 MiB  server_rendering  [emitted] [immutable]  server_rendering
webpack     | js/server_rendering-13527221e10c2e65c45f.js.map   1.88 MiB  server_rendering  [emitted] [dev]        server_rendering
webpack     |                                   manifest.json  738 bytes                    [emitted]
webpack     | ℹ 「wdm」: Compiled successfully.
app         | Started GET "/" for 172.22.0.1 at 2021-06-26 16:39:02 +0000
app         |    (0.7ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
app         | Processing by HomeController#index as HTML
app         |   Rendering layout layouts/application.html.erb
app         |   Rendering home/index.html.erb within layouts/application
app         |   Post Load (0.8ms)  SELECT "posts".* FROM "posts"
app         |   ↳ app/views/home/index.html.erb:1
app         |   Rendered home/index.html.erb within layouts/application (Duration: 13.2ms | Allocations: 12811)
app         | [Webpacker] Everything's up-to-date. Nothing to do
app         |   Rendered layout layouts/application.html.erb (Duration: 17.8ms | Allocations: 17655)
app         | Completed 200 OK in 24ms (Views: 15.3ms | ActiveRecord: 3.7ms | Allocations: 21885)
app         |
app         |
app         | Started GET "/packs/js/application-6527e9c4b100bc10bc71.js" for 172.22.0.1 at 2021-06-26 16:39:02 +0000
app         |
app         | ActionController::RoutingError (No route matches [GET] "/packs/js/application-6527e9c4b100bc10bc71.js"):

Dockerfile

代码语言:javascript
运行
复制
FROM ruby:3.0.1

ENV APP_PATH /app
ENV BUNDLE_VERSION 2.2.21
ENV BUNDLE_PATH /usr/local/bundle/gems
ENV TMP_PATH /tmp/
ENV RAILS_LOG_TO_STDOUT true
ENV RAILS_PORT 3000

# copy entrypoint scripts and grant execution permissions
COPY ./dev-docker-entrypoint.sh /usr/local/bin/dev-entrypoint.sh
COPY ./webpack-entrypoint.sh /usr/local/bin/webpack-entrypoint.sh
COPY ./test-docker-entrypoint.sh /usr/local/bin/test-entrypoint.sh
RUN chmod +x /usr/local/bin/dev-entrypoint.sh && \
        chmod +x /usr/local/bin/test-entrypoint.sh && \
        chmod +x /usr/local/bin/webpack-entrypoint.sh

# install dependencies for application
RUN apt update -qq && apt install -y \
        curl \
        libpq-dev \
        imagemagick \
        && mkdir -p $APP_PATH 

# Install node js
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash -
RUN apt-get update && apt-get install -y nodejs

# install yarn
RUN npm i -g yarn

RUN gem install bundler --version "$BUNDLE_VERSION" \
&& rm -rf $GEM_HOME/cache/*

RUN yarn install

# navigate to app directory
WORKDIR $APP_PATH

EXPOSE $RAILS_PORT

ENTRYPOINT [ "bundle", "exec" ]

docker-compose.yml

代码语言:javascript
运行
复制
version: '3'
volumes:
  db_data:
  gem_cache:
  shared_data:
services:
  redis:
    image: redis:alpine
    command: redis-server
    volumes:
      - shared_data:/var/shared/redis
  postgres:
    image: postgres:11.11
    container_name: postgres
    volumes:
      - db_data:/var/lib/postgresql/data
      - shared_data:/var/shared
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
    ports:
      - 5099:5432
  webpack:
    build:
      context: .
      dockerfile: Dockerfile.dev
    container_name: webpack
    entrypoint: webpack-entrypoint.sh
    command: ['./bin/webpack-dev-server']
    volumes:
      - .:/app
      - shared_data:/var/shared
      - gem_cache:/usr/local/bundle/gems
    ports:
      - 3035:3035
  app:
    build:
      context: .
      dockerfile: Dockerfile.dev
    container_name: app
    volumes:
      - .:/app
      - shared_data:/var/shared
      - gem_cache:/usr/local/bundle/gems
    ports:
      - 3000:3000
    stdin_open: true
    tty: true
    env_file: .env.development
    entrypoint: dev-entrypoint.sh
    command: ['rails', 'server', '-p', '3000', '-b', '0.0.0.0']
    environment:
      RAILS_ENV: development
    depends_on:
      - webpack
      - postgres

*-entrypoint.sh文件非常简单

代码语言:javascript
运行
复制
#!/bin/sh

set -e

echo "Environment: $RAILS_ENV"

# install missing gems
bundle check || bundle install --jobs 20 --retry 5

# run passed commands
bundle exec ${@}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-26 16:53:18

我希望这会对其他人有所帮助。

尽管查看日志都很好,webpack似乎正在编译,但问题在于webpacker.yml文件中webpack的webpacker.yml配置。

默认webpack.yml配置

代码语言:javascript
运行
复制
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/**'

dev_server localhost webpack 主机

注:在我的情况下是webpack,因为我的名字是webpack码头集装箱。

代码语言:javascript
运行
复制
development:
  <<: *default
  compile: true

  # Reference: https://webpack.js.org/configuration/dev-server/
  dev_server:
    https: false
    host: webpack
    port: 3035
    public: webpack: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/**'

config/initializers/content_security_policy.rb中指定webpack主机在connect_src

代码语言:javascript
运行
复制
    policy.connect_src :self, :https, "http://webpack:3035", "ws://webpack:3035" if Rails.env.development?
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68144505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档