0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Rails6】generateコマンドでyarnエラー

Posted at

内容

  • Rails6でgenerateコマンドを打ったらyarnエラーが発生したのでその対処法
  • 対処法と言ってもエラー内容に従って解決しただけです(もし原因ご存じの方がいたらご教示ください)

環境

  • macOS Mojave 10.14.6
  • VirtualBox 6.0.10
  • Vagrant 2.2.5
  • centos/7 (virtualbox, 1905.1)
  • rbenv 1.1.2-4-g577f046
  • ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
  • Rails 6.0.0

エラー内容

# エラーを発生させたコマンド
bin/rails generate controller {samples}



# エラー内容
/usr/share/yarn/lib/cli.js:46099
  let {
      ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/share/yarn/bin/yarn.js:24:13)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)


========================================
  Your Yarn packages are out of date!
  Please run `yarn install --check-files` to update.
========================================


To disable this check, please change `check_yarn_integrity`
to `false` in your webpacker config file (config/webpacker.yml).

やったこと

Please run 'yarn install --check-files' to update. とあったので次のコマンドを実行

$ yarn install --check-files


# 結果
/usr/share/yarn/lib/cli.js:46099
  let {
      ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/share/yarn/bin/yarn.js:24:13)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

そもそもyarn -vなどのyarnコマンド全てで同じ結果でした。

解決

please change 'check_yarn_integrity' to 'false' in your webpacker config file (config/webpacker.yml)
とあったので、config/webpacker.ymlを編集して該当項目をtrue->falseへ変更

config/webpacker.yml
# Note: You must restart bin/webpack-dev-server for changes to take effect
...略

development:
  <<: *default
  compile: true

  # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
-  check_yarn_integrity: true
+  check_yarn_integrity: false

...略

やってみる

$ bin/rails generate controller samples
Running via Spring preloader in process 25275
      create  app/controllers/samples_controller.rb
      invoke  erb
      create    app/views/samples
      invoke  test_unit
      create    test/controllers/samples_controller_test.rb
      invoke  helper
      create    app/helpers/samples_helper.rb
      invoke    test_unit
      invoke  assets
      invoke    scss
      create      app/assets/stylesheets/samples.scss

generateコマンドは無事通りましたがyarnコマンドは使えないままです。
原因ご存じの方はご教示ください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?