I'm trying to build a gatsby static website from an Azure Dev ops build definition.
AzureDev ops provides a gulp task so I'm trying to create a simple gulpfile to wrap the build process of gatsby.
Right now I tried :
const gatbsyCli = require('gatsby-cli/lib/create-cli');
function gatsbyBuild() {
gatbsyCli([ 'build' ]);
}
exports.gatsbyBuild = gatsbyBuild;
However, the task only show the command line help:
Usage: gulp.js <command> [options]
Commands:
gulp.js develop Start development server. Watches files, rebuilds, and hot reloads if something
changes
gulp.js build Build a Gatsby project.
gulp.js serve Serve previously built Gatsby site.
gulp.js info Get environment information for debugging and issue reporting
gulp.js repl Get a node repl with context of Gatsby environment, see (add docs link here)
gulp.js new [rootPath] [starter] Create new Gatsby project.
Options:
--verbose Turn on verbose output [boolean] [default: false]
--no-color Turn off the color in output [boolean] [default: false]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Pass --help to see all available commands and options.
[22:28:15] The following tasks did not complete: gatsbyBuild
[22:28:15] Did you forget to signal async completion?
How to build a gatsby site from gulp ?
Is there any better way to reach my goal ?
[Edit] Also tried:
const gatbsyBuildImpl = require('gatsby/dist/commands/build.js');
function gatsbyBuild() {
gatbsyBuildImpl();
}
exports.gatsbyBuild = gatsbyBuild;
but fails with TypeError: Cannot read property 'openTracingConfigFile' of undefined
[/Edit]
[Edit 2019-02-02] Regarding answers, here's update regarding my progress.
First, I try to use NPM action to build the site, as suggested.
However, it fails with the following error:
2019-02-02T21:13:22.3306376Z [command]/usr/local/bin/npm run build
2019-02-02T21:13:27.6097839Z error GraphQL Error There was an error while compiling your site's GraphQL queries.
2019-02-02T21:13:27.6098171Z
2019-02-02T21:13:27.6099612Z Error: RelayParser: Encountered duplicate defintitions for one or more documents: each document must have a unique name. Duplicated documents:
2019-02-02T21:13:27.6100019Z > [email protected] build /home/vsts/work/1/s
2019-02-02T21:13:27.6100847Z - DefaultSEOQuery
2019-02-02T21:13:27.6100902Z > gatsby build
However, I don't understand this error. The site perfectly builds locally.
My gatbsy-node.js query is :
`
{
allMarkdownRemark(sort: {fields: [frontmatter___date], order: DESC}, limit: 1000) {
edges {
node {
fields {
slug
}
frontmatter {
title
}
}
}
cats: group(field: frontmatter___categories, limit:1000) {
fieldValue
totalCount
}
tags: group(field: frontmatter___tags, limit:1000) {
fieldValue
totalCount
}
}
}
Also, here's my yaml definition :
resources:
- repo: self
queue:
name: Hosted Ubuntu 1604
demands: npm
steps:
- task: Npm@1
displayName: 'npm install'
inputs:
verbose: false
- task: Npm@1
displayName: 'npm custom'
inputs:
command: custom
verbose: false
customCommand: 'run build'
Moving to "Hosted" agent, throw another error:
019-02-02T21:52:17.2419822Z [0m
2019-02-02T21:52:17.2419867Z [0m [0m[97m[41mError[0m[37m[41m:[0m[37m[41m [0m[97m[41m0-0cf4e58448448331aa6c.js from Terser[0m
2019-02-02T21:52:17.2421623Z [0m [0m[97m[41mTypeError: Cannot read property 'minify' of undefined[0m
2019-02-02T21:52:17.2421678Z [0m [0m[97m[41m at minify (D:\a\1\s\node_modules\terser-webpack-plugin\dist\minify.js:175:[0m [0m[97m[41m22)[0m
2019-02-02T21:52:17.2421746Z [0m [0m[97m[41m at TaskRunner.boundWorkers.error [as boundWorkers] (D:\a\1\s\node_modules\[0m [0m[97m[41mterser-webpack-plugin\dist\TaskRunner.js:68:40)[0m
2019-02-02T21:52:17.2421794Z [0m [0m[97m[41m at enqueue (D:\a\1\s\node_modules\terser-webpack-plugin\dist\TaskRunner.js[0m [0m[97m[41m:89:14)[0m
2019-02-02T21:52:17.2421841Z [0m [0m[97m[41m at tryCatcher (D:\a\1\s\node_modules\bluebird\js\release\util.js:16:23)[0m
2019-02-02T21:52:17.2421906Z [0m [0m[97m[41m at Promise._settlePromiseFromHandler (D:\a\1\s\node_modules\bluebird\js\re[0m [0m[97m[41mlease\promise.js:512:31)[0m
2019-02-02T21:52:17.2421954Z [0m [0m[97m[41m at Promise._settlePromise (D:\a\1\s\node_modules\bluebird\js\release\promi[0m [0m[97m[41mse.js:569:18)[0m
2019-02-02T21:52:17.2422390Z [0m [0m[97m[41m at Promise._settlePromise0 (D:\a\1\s\node_modules\bluebird\js\release\prom[0m [0m[97m[41mise.js:614:10)[0m
2019-02-02T21:52:17.2422463Z [0m [0m[97m[41m at Promise._settlePromises (D:\a\1\s\node_modules\bluebird\js\release\prom[0m [0m[97m[41mise.js:690:18)[0m
2019-02-02T21:52:17.2422512Z [0m [0m[97m[41m at _drainQueueStep (D:\a\1\s\node_modules\bluebird\js\release\async.js:138[0m [0m[97m[41m:12)[0m
2019-02-02T21:52:17.2422560Z [0m [0m[97m[41m at _drainQueue (D:\a\1\s\node_modules\bluebird\js\release\async.js:131:9)[0m
2019-02-02T21:52:17.2422626Z [0m [0m[97m[41m at Async._drainQueues (D:\a\1\s\node_modules\bluebird\js\release\async.js:[0m [0m[97m[41m147:5)[0m
2019-02-02T21:52:17.2422677Z [0m [0m[97m[41m at Immediate.Async.drainQueues (D:\a\1\s\node_modules\bluebird\js\release\[0m [0m[97m[41masync.js:17:14)[0m
2019-02-02T21:52:17.2422769Z [0m [0m[97m[41m at runCallback (timers.js:637:20)[0m
2019-02-02T21:52:17.2422832Z [0m [0m[97m[41m at tryOnImmediate (timers.js:610:5)[0m
2019-02-02T21:52:17.2422878Z [0m [0m[97m[41m at processImmediate [as _immediateCallback] (timers.js:582:5)[0m
npm ERR! Failed at the [email protected] build script 'gatsby build'.
2019-02-02T21:52:17.2430701Z npm ERR! Make sure you have the latest version of node.js and npm installed.
2019-02-02T21:52:17.2430849Z npm ERR! If you do, this is most likely a problem with the gatsby-starter-blog package,
2019-02-02T21:52:17.2431116Z npm ERR! not with npm itself.