LoginSignup
10
2

More than 5 years have passed since last update.

Hugoで作成したサイトをNetlifyでデプロイしようとしたが、「No source directory found」と出力されて失敗した時の対応

Last updated at Posted at 2018-01-02

起こったこと

Hugoで作成したサイトをNetlifyでデプロイしようとしましたが、ログに「No source directory found」と出力されて失敗しました。

検索して調べたところ、中々エラー原因が見つからなかったので、こちらで知見として共有します。

デプロイ時のログ

※ 「自分が作成したリポジトリ名」以外の箇所は原文のままで貼り付けています。

12:59:38 AM: Build ready to start
12:59:38 AM: Fetching cached dependencies
12:59:38 AM: No cached dependencies found. Cloning fresh repo
12:59:39 AM: git clone git@bitbucket.org:自分が作成したリポジトリ名
12:59:40 AM: Preparing Git Reference refs/heads/master
12:59:43 AM: Running build command: hugo --theme=hugo-freelancer-theme --buildDrafts
12:59:44 AM: Downloading and installing node v6.12.2...
12:59:45 AM: Downloading https://nodejs.org/dist/v6.12.2/node-v6.12.2-linux-x64.tar.xz...
12:59:45 AM: 
                                                                           0.0%
12:59:45 AM: 
12:59:45 AM:                     1.1%
12:59:45 AM: 
###
12:59:45 AM:           4.9%
12:59:45 AM: 
#############
12:59:45 AM:  19.2%
12:59:45 AM: 
#############################                                             41.6%
12:59:46 AM: 
##########################################################
12:59:46 AM:  81.3%
12:59:46 AM: 
##############################################################
12:59:46 AM: ########## 100.0%
12:59:46 AM: 
12:59:46 AM: Computing checksum with sha256sum
12:59:46 AM: Checksums matched!
12:59:48 AM: Now using node v6.12.2 (npm v3.10.10)
12:59:48 AM: Using version v6.12.2 of node
12:59:49 AM: Using /opt/buildhome/.rvm/gems/ruby-2.1.2
12:59:49 AM: Installing Hugo 0.30.2
12:59:51 AM: Started building sites ...
12:59:51 AM: Error: Error building site: No source directory found, expecting to find it at /opt/build/repo/content
12:59:52 AM: Build complete: exit code: 255
12:59:52 AM: Cleaning up docker container
12:59:52 AM: Error running command: Build script returned non-zero exit code: 255
12:59:52 AM: An error occurred while building the site, skipping the deploy and cache refresh.
12:59:53 AM: Build script returned non-zero exit code: 255
12:59:54 AM: Finished processing build request in 15.575860704s

エラーの原因

具体的にエラーの原因が指摘されているのは以下の箇所です。

Error: Error building site: No source directory found, expecting to find it at /opt/build/repo/content

Getting Hugo running on Netlify という記事の『Adding empty folders to git』の項目に書いてあることによると、どうやら、ルート直下にあるディレクトリ(archetypes, content, data, layouts, static)のいずれかでファイルが存在しないディレクトリがあると、Netlifyでbuildができないとのことでした。

以下は上記について説明している箇所の引用です。

Wait, so why weren’t the other folders - archetypes, content, data, layouts, static - added? Well, they’re empty. Hugo likes empty folders. Git doesn’t. If you want to keep them, you’ll need to add a file into each of them. To do this, you can use a convention of having an empty file called .gitkeep.

Why is this important? Because Netlify needs those folders. Let’s look at the build on Netlify, which has since failed:

なお、自分の状況の場合、hugo-freelancer-theme というthemeを使用したのですが、デプロイ時にcontentディレクトリ内にファイルが存在していなかったことがエラーが出た原因でした。

対応

ファイルが存在しないディレクトリに.gitkeepファイルを追加して、リモートリポジトリに反映するとデプロイができるようになりました。

10
2
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
10
2