(<unknown>):找不到预期的&#39;:&#39;在第3行第1列扫描一个简单的键时(Psych :: SyntaxError)

时间:2015-09-07 14:45:13

标签: ruby-on-rails ruby git

我正在尝试在从git中提取的rails项目上运行bundle install。当我运行bundle install时,我收到以下错误:

    /Users/jordandeutsch/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/psych.rb:370:in     `parse': (<unknown>): could not find expected ':' while scanning a simple key at     line 3 column 1 (Psych::SyntaxError)
    from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/psych.rb:370:in `parse_stream'
    from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/psych.rb:318:in `parse'
    from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/psych.rb:245:in `load'
    from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/config_file.rb:333:in `load_file'
    from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/config_file.rb:198:in `initialize'
    from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/gem_runner.rb:74:in `new'
    from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/gem_runner.rb:74:in `do_configuration'
    from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/gem_runner.rb:39:in `run'
    from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.1/bin/gem:21:in `<main>'

这是我的Gemfile:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.3'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'

#for Authentification
gem 'devise'

#for image management
gem 'paperclip', :git => 'git://github.com/thoughtbot/paperclip.git'
gem 'aws-sdk-v1'
gem 'aws-s3'

group :development do
    gem 'better_errors'
end

group :development, :test do
    gem 'dotenv-rails'
end
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more:     https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger     console
  gem 'byebug'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the      background. Read more: https://github.com/rails/spring
  gem 'spring'
end

经过一番挖掘后,我认为这可能是rvm的一个问题,因为我试图从git中删除一个旧项目,但仍然无法运行bundle install。我还尝试在本地复制项目并运行安装并启动一个新项目都没有成功。

重新安装rvm后我运行rvm use ruby --install --default并收到以下错误(类似于上面的内容)

/Users/jordandeutsch/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych.rb:370:in `parse': (<unknown>): could not find expected ':' while scanning a simple key at line 3 column 1 (Psych::SyntaxError)
from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych.rb:370:in `parse_stream'
from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych.rb:318:in `parse'
from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/psych.rb:245:in `load'
from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/config_file.rb:333:in `load_file'
from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/config_file.rb:198:in `initialize'
from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/gem_runner.rb:74:in `new'
from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/gem_runner.rb:74:in `do_configuration'
from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/gem_runner.rb:39:in `run'
from /Users/jordandeutsch/.rvm/rubies/ruby-2.2.3/bin/gem:25:in `<main>'

基本上我无法在计算机上开始新的rails项目。任何见解将不胜感激。

4 个答案:

答案 0 :(得分:35)

如果.yml文件中存在语法错误,通常会出现此错误。 看看你是否能找到任何错误。

您也可以尝试从主目录中删除.gemrc文件。可能是错误在那里。

答案 1 :(得分:0)

我最近遇到过这个问题。我的问题:

.application.yml

default: &default
 FOO_KEY: 'XXXXX'

development:
  <<: *default

test:
  <<: *default

工作得很好。

default: &default
  FOO_KEY: 'asdf'
  BAR_KEY: 'XXXXXXXXXXX'
  FOO_BAR: 'XXXXXXXXXXXX'

development:
  <<: *default

test:
  <<: *default

没用。我尝试了什么:

  • 重写application.yml
  • 删除GEMFILE.lock并重新安装所有宝石
  • 更改键的值和名称
  • 检查拼写错误的所有配置

这些都没有帮助解决问题。因此,作为一名优秀的工程师,我把它烧成了地面。我将我的项目克隆到一个新目录并重新编写application.yml,这很有用。两个repos都在同一个分支上,并且在同一个变更集上。

答案 2 :(得分:0)

如果您仍在寻找答案(多次修补了database.yml之后),请尝试检查在应用程序初始化时加载的其他yml文件,例如secrets.yml,{ {1}},sidekiq.yml左右。

在我的情况下,它引发了如下错误:

webpacker.yml

但是/home/abhishek/.rvm/gems/ruby-2.3.7/gems/railties-4.2.10/lib/rails/application/configuration.rb:115:in `rescue in database_configuration': YAML syntax error occurred while parsing /home/abhishek/Workspace/clearfunds/clearfunds-web/config/database.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (<unknown>): could not find expected ':' while scanning a simple key at line 19 column 7 (RuntimeError) 是完整的。问题出在database.yml中。在几个地方都使用过secrets.yml缩进。

答案 3 :(得分:0)

对于其他遇到此错误的人,我遇到了此错误,结果发现存在不可见的unicode字符正在引起冲突。我找到了一个网站,显示这些字符在哪里:https://www.soscisurvey.de/tools/view-chars.php