Rails + Webpack: Errno::EPERM at / (Operation Not Permitted)

Rails + Webpack: Errno::EPERM at / (Operation Not Permitted)

我正在尝试 运行 一个使用 React 和 webpacker 的 rails 应用程序。所有 node_modules 都是通过 yarn 安装的。

当我使用 foreman 启动本地服务器时,出现错误:

Errno::EPERM - Operation not permitted - /private/var/db/ConfigurationProfiles/Store:

yarn.lock:

"@rails/webpacker@3.4":
  version "3.4.3"
  resolved "https://registry.yarnpkg.com/@rails/webpacker/-/webpacker-3.4.3.tgz#496a5d49bea8856db20b212d2727a4b43b281dd9"
  dependencies:
    babel-core "^6.26.0"
    babel-loader "^7.1.2"
    babel-plugin-syntax-dynamic-import "^6.18.0"
    babel-plugin-transform-class-properties "^6.24.1"
    babel-plugin-transform-object-rest-spread "^6.26.0"
    babel-polyfill "^6.26.0"
    babel-preset-env "^1.6.1"
    case-sensitive-paths-webpack-plugin "^2.1.1"
    compression-webpack-plugin "^1.1.10"
    css-loader "^0.28.9"
    extract-text-webpack-plugin "^3.0.2"
    file-loader "^1.1.6"
    glob "^7.1.2"
    js-yaml "^3.10.0"
    node-sass "^4.7.2"
    path-complete-extname "^1.0.0"
    postcss-cssnext "^3.1.0"
    postcss-import "^11.0.0"
    postcss-loader "^2.1.0"
    sass-loader "^6.0.6"
    style-loader "^0.20.1"
    uglifyjs-webpack-plugin "^1.1.8"
    webpack "^3.10.0"
    webpack-manifest-plugin "^1.3.2"

Package.json:

{
  "dependencies": {
    "@rails/webpacker": "3.4",
    "babel-preset-react": "^6.24.1",
    "prop-types": "^15.6.1",
    "react": "^16.3.2",
    "react-dom": "^16.3.2",
    "react-on-rails": "11.0.2",
    "react_ujs": "^2.4.4",
    "wallet-address-validator": "^0.1.7"
  },
  "devDependencies": {
    "webpack-dev-server": "2.11.2"
  }
}

宝石文件:

source 'https://rubygems.org'
ruby "2.5.0"

gem 'active_model_otp', "~> 1.2"
gem "active_model_serializers", "~> 0.10"
gem 'attr_encrypted', "~> 3.1"
gem 'bcrypt', "~> 3.1"
gem 'bootsnap', "~> 1.1", require: false
gem 'bulma-rails', "~> 0.6"
gem 'devise', "~> 4.4"
gem 'faker', "~> 1.8"
gem 'fast_jsonapi', "~> 1.0"
gem 'font-awesome-sass', '~> 4.0'
gem 'foreman', "~> 0.64"
gem 'hashie', "~> 3.5"
gem 'httparty', "~> 0.16"
gem 'jquery-rails', "~> 4.3"
gem 'mini_racer', platforms: :ruby
gem 'omniauth-google-oauth2', "~> 0.5"
gem 'pg', "~> 1.0"
gem 'puma', "~> 3.11"
gem 'pundit', "~> 1.1"
gem 'rails', '~> 5.2.0'
gem 'rails_admin'
gem "react_on_rails", "11.0.0"
gem 'rqrcode', "~> 0.10"
gem 'sass-rails', "~> 5.0"
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
gem 'uglifier', "~> 4.1"
gem "webpacker", "~> 3.4"

group :development, :test do
  gem 'better_errors', "~> 2.4"
  gem 'binding_of_caller', "~> 0.8"
  gem 'bullet', "~> 5.7"
  gem 'byebug', "~> 10.0"
  gem 'listen'
  gem 'letter_opener', "~> 1.6"
  gem 'meta_request', "~> 0.5"
  gem 'spring', "~> 2.0"
  gem 'spring-commands-rspec', "~> 1.0"
  gem 'web-console', "~> 3.5"
end

group :test do
  gem 'factory_bot_rails', "~> 4.8"
end

config/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

  # 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:
    - .jsx
    - .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:

#!/usr/bin/env ruby

ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"]  ||= ENV["NODE_ENV"] || "development"

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
  Pathname.new(__FILE__).realpath)

require "rubygems"
require "bundler/setup"

require "webpacker"
require "webpacker/webpack_runner"
Webpacker::WebpackRunner.run(ARGV)

bin/yarn:

#!/usr/bin/env ruby
APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(APP_ROOT) do
  begin
    exec "yarnpkg", *ARGV
  rescue Errno::ENOENT
    $stderr.puts "Yarn executable was not detected in the system."
    $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
    exit 1
  end
end

app/javascripts/application.js 和 app/javascripts/server_rendering.js

var componentRequireContext = require.context("components", true)
var ReactRailsUJS = require("react_ujs")
ReactRailsUJS.useContext(componentRequireContext)

应用程序在这一行挂起:

<%= javascript_pack_tag 'application' %>

我认为这是一个文件系统问题,所以我重新安装了 macos,认为我可能搞砸了某些东西的权限。我不知道发生了什么。

刚打的一样。如果你看一下堆栈跟踪,你会发现它在这里令人窒息:

files = Dir[*default_watched_paths, *watched_paths].reject { |f| File.directory?(f) }

罪魁祸首在 webpacker.yml - 您需要将 resolved_paths: [''] 更改为 resolved_paths: [] 并且您的问题应该得到解决:)