Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8913

Ubuntuにインストールしたyarnが実行できない

$
0
0

Ubuntuにインストールしたyarnが実行できない

Ubuntu 16.04に最新のyarnをインストールした際、yarnコマンドを実行すると以下のようなエラーが発生しました。

$ yarn -v
/usr/share/yarn/lib/cli.js:46099
  let {
      ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/share/yarn/bin/yarn.js:24:13)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)

yarnと関係ありそうなものとして、Nodejsがあるので、Nodejsのバージョンを確認します。

$ nodejs -v
v4.2.6

そういえば、レポジトリを更新しない状態でapt install nodejsをすると、古いバージョンがインストールされるようだった気がします。

yarnの公式HPを確認すると、Nodeのバージョンが4.8.0以上となっていました。
いつの間に!
Yarn公式HP

なので、今回はバージョン10系のnodejsがインストールできるように、レポジトリを追加します。
そして、インストール済みのnodejsを削除して、新しいnodejsをインストールします。
コマンドは以下の様になります。

*最新のバージョンをインストールしたい場合は、curlコマンドのurl部分を変更してください。
例) バージョン12系をインストールしたい
-> curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
$ sudo apt remove nodejs
$ sudo apt install nodejs

これで、yarnコマンドが実行できれば、解決です。

$ yarn -v
1.21.1

お疲れさまでした。


Viewing all articles
Browse latest Browse all 8913

Trending Articles