ruby-on-rails React在Rails项目内部部署到Heroku时收到错误cp:“es 20 client/build/.public/”后缺少目标文件操作数“

y1aodyip  于 2023-01-14  发布在  Ruby
关注(0)|答案(1)|浏览(69)

我是一名编码训练营开发人员,一直在努力在Web应用程序中实现身份验证。我制作过使用API调用的应用程序,但一直在学习和实践其他编码概念。我发现我可以将React项目放入Rails项目中,并将一个完整的堆栈项目部署到Heroku。这有助于我解决使用会话和令牌进行安全API调用的问题。我即将开始在Heroku上非本地配置项目,并尝试再次实现用于身份验证的会话和cookie组合。

  • 根Rails目录软件包. json { "name": "heroku-deploy", "descriptions": "Build scripts for Heroku", "engine": { "node": "18.12.1" }, "scripts": { "clean": "rm -rf public", "build": "npm install --prefix es20client && npm run build --prefix es20client", "deploy": "cp -a es20client/build/.public/", "heroku-postbuild": "npm run clean && npm run build && npm run deploy" } }
  • 根Rails目录Gemfile
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.0.0"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.4"

# Use postgresql as the database for Active Record
gem "pg", "~> 1.1"
gem "bcrypt"
# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem "rack-cors"
gem 'active_model_serializers'

group :development, :test do
  # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
  gem "debug", platforms: %i[ mri mingw x64_mingw ]
end

group :development do
  # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
  # gem "spring"
end
  • 根Rails目录/es20client/软件包. json
{
  "name": "es20client",
  "version": "0.1.0",
  "private": true,
  "proxy": "http://localhost:3000",
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "axios": "^1.2.1",
    "dotenv": "^16.0.3",
    "final-form": "^4.20.7",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-final-form": "^6.5.9",
    "react-redux": "^8.0.5",
    "react-router-dom": "^5.3.4",
    "react-scripts": "5.0.1",
    "reactjs-popup": "^2.0.5",
    "redux": "^4.2.0",
    "redux-thunk": "^2.4.2",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "PORT=4000 react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

我似乎在尝试创建React客户端的生产构建的项目和运行部署以将es20client/build的内容复制到public/的npm之间遇到了错误
Build Failed之前的最后几行是"cp:"es20client/build/. public/"后面缺少目标文件操作数""有关详细信息,请尝试" cp--help "。"
并运行:cp-帮助
退货:
cp:非法选项---用法:cp [-R [-H|- L|- P]][-fi|- n][-aclpsvXx]源文件目标文件cp [-R [-H|- L|- P]][-fi|- n][-aclpsvXx]源文件...目标目录
附上一些文件。

  • heroku推送日志最后一个
remote: -----> Build
remote:        Detected both "build" and "heroku-postbuild" scripts
remote:        Running heroku-postbuild
remote:        
remote:        > heroku-postbuild
remote:        > npm run clean && npm run build && npm run deploy
remote:        
remote:        
remote:        > clean
remote:        > rm -rf public
remote:        
remote:        
remote:        > build
remote:        > npm install --prefix es20client && npm run build --prefix es20client

...more lines of code...

remote:          npm install -g serve
remote:          serve -s build
remote:        
remote:        Find out more about deployment here:
remote:        
remote:          https://cra.link/deployment
remote:        
remote:        
remote:        > deploy
remote:        > cp -a es20client/build/.public/
remote:        
remote: cp: missing destination file operand after 'es20client/build/.public/'
remote: Try 'cp --help' for more information.
remote: 
remote: -----> Build failed
n6lpvg4x

n6lpvg4x1#

看起来我只是需要在根Rails package.json中的“cp -a es 20 client/build/.public/”中的.“”和“public”之间留一个空格。我得到了一个新的错误,它看起来更友好。

相关问题