ほねっとのぶろぐ

アニメとAndroidが好きなほねっとのブログです。

DockerのUbuntuコンテナにServerless入れようとしたら、npmではなくyarnが必要になるのでその手順

DockerのUbuntuコンテナにServerlessの手順に従って入れようとすると、以下のエラーが出る

参考にしたページ https://www.serverless.com/examples/aws-node-puppeteer

npmででたエラー

sh: 1: node: Permission denied
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/serverless/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"l
inux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! protobufjs@6.10.1 postinstall: `node scripts/postinstall`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the protobufjs@6.10.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-10-11T14_46_17_530Z-debug.log

yarnが正しく動かない

npmがダメならyarnでしょう、ということでyarnを入れようとしたらこれもまたハマってしまう。

root@54ecd4462e57:~# apt install yarn
root@54ecd4462e57:~# yarn global add serverless
00h00m00s 0/0: : ERROR: [Errno 2] No such file or directory: 'global'
root@54ecd4462e57:~# yarn --version
0.32+git

yarnを正しくインストールする

yarnのバージョンが変だ。 調べてみたところ、どうやらUbuntuの特定バージョンでは、yarnがcmdtestになってしまうらしい。 https://github.com/yarnpkg/yarn/issues/2821

ということで、まずyarn(cmdtest)を消す。 途中でgnupgがないって言われたので、それも入れる。 さらに途中でタイムゾーン聞かれたので、Asia->Tokyoを指定。

apt remove yarn
apt install gnupg
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install yarn

そうすると、yarnが無事入る。

root@54ecd4462e57:~# yarn -v
1.22.5

うん、ちゃんとしたバージョンになってる。

Serverlessをyarnで入れる

Serverless入れる。 https://www.serverless.com/examples/aws-node-puppeteer に従う(ただし、npmはyarnになってる)

yarn global add serverless
serverless install -u https://github.com/serverless/examples/tree/master/aws-node-puppeteer -n  aws-node-puppeteer

以上!