Comments (26)
I figured it out! Two things were at play:
-
My Algolia trail expired. I needed to switch to a community plan, or a paid plan. My account was in limbo. (hence
gatsby develop
no longer working.) -
When I run
gatsby develop
my.env
file is used.
When I rungatsby build
the app searches for a.env.production
file, and I did not have one. Creating the.env.production
and putting my credentials in that file did the trick.
Thanks for your help @Haroenv .
from gatsby-plugin-algolia.
Thanks @Isaac-Tait! We figured it out. Turns out that Netlify triggers another build on another account hence it fails on those builds because no env variables were set up in Netlify
from gatsby-plugin-algolia.
Hey @Haroenv, Thanks for getting back to me so quickly. Yes it does consistently fail. BUT I plugged the credentials directly into the gatsby-config file (instead of calling it from my .env file) and it worked!
- How would I go about logging the appid and apikey before instantiating the plugin?
- How would I go about debugging why gatsby isnt reading from my .env file?
Thanks for your patience - I am fairly new to all of this.
from gatsby-plugin-algolia.
Whether you're on the free version of Algolia or not doesn't make a difference @lettie16. Did you pass the environment variables to Gatsby cloud? Can you try logging out the values that you pass to the plugin to see if they're set?
I would imagine they would have been passed as we also have Contentful variables being passed. But I didn't set up the environment so not sure. Where do I need to look to see if they are being passed to Gatsby Cloud. They are definitely in the .env.production file
All sorted cheers. Although as a note should anyone else stumble upon this issue. Once the variables were added I still had errors with undefined. This was resolved by create Gatsby_ pre-fixed env vars which were needed for Gatsby Cloud to find them.
from gatsby-plugin-algolia.
@Isaac-Tait in netlify we have both the GATSBY_ prefix and the standard Algolia VARS set up and it is working fine. I think but I may be wrong you need the GATSBY_ ones so Gatsby can build it and the standard Algolia ones so it works when it's built. You would also need both in your .env file as well.
from gatsby-plugin-algolia.
the values of the environment is kept secret (which is good, don't post that publicly), but I assume the value isn't right
from gatsby-plugin-algolia.
Does this consistently fail? Can you log the appId & apiKey before instantiating the plugin?
from gatsby-plugin-algolia.
// in Gatsby-config.js
console.log(process.env); // should show all registered env variables
from gatsby-plugin-algolia.
¡Me lo imaginé! Dos cosas estaban en juego:
- Mi rastro de Algolia expiró. Necesitaba cambiarme a un plan comunitario o un plan pagado. Mi cuenta estaba en el limbo. (Por lo tanto,
gatsby develop
ya no funciona).- Cuando ejecuto
gatsby develop
mi.env
archivo se utiliza.
Cuando ejecutogatsby build
la aplicación busca un.env.production
archivo, y no tenía uno. Crear.env.production
y poner mis credenciales en ese archivo fue el truco.Gracias por tu ayuda @Haroenv .
Hello, my site uses Netlify connected to github, obviously I cannot upload my credentials ".env.production" to github, you can see the environment variables to netlify. What is the solution?
from gatsby-plugin-algolia.
You put your environment variables in the Netlify control panel (build settings)
from gatsby-plugin-algolia.
Having the same issue as original poster. Checked .env variables are there for both production and development and I'm running the Alogolia Free version for testing and well within limits. Everything works fine in develop so do we know if the Free version would be effecting this in a production build on Gatsby Cloud?
from gatsby-plugin-algolia.
Whether you're on the free version of Algolia or not doesn't make a difference @lettie16. Did you pass the environment variables to Gatsby cloud? Can you try logging out the values that you pass to the plugin to see if they're set?
from gatsby-plugin-algolia.
Whether you're on the free version of Algolia or not doesn't make a difference @lettie16. Did you pass the environment variables to Gatsby cloud? Can you try logging out the values that you pass to the plugin to see if they're set?
I would imagine they would have been passed as we also have Contentful variables being passed. But I didn't set up the environment so not sure. Where do I need to look to see if they are being passed to Gatsby Cloud. They are definitely in the .env.production file
from gatsby-plugin-algolia.
glad to hear you've sorted this, and thanks for letting everyone who bumps into this next of the solution @lettie16, I haven't used Gatsby cloud before, so didn't know about this limitation
from gatsby-plugin-algolia.
I am running into this issue as well.
When I run gatsby build
I am returning this error:
ERROR #11321 PLUGIN
"gatsby-plugin-algolia" threw an error while running the onPostBuild lifecycle:
Please provide an application ID. Usage: algoliasearch(applicationID, apiKey, opts)
44 | }
45 |
> 46 | const client = algoliasearch(appId, apiKey);
| ^
47 |
48 | setStatus(activity, `${queries.length} queries to index`);
49 |
File: node_modules/gatsby-plugin-algolia/gatsby-node.js:46:18
AlgoliaSearchError: Please provide an application ID. Usage: algoliasearch(applicationID, apiKey, opts)
AlgoliaSearchCore.js:50 AlgoliaSearchNodeJS.AlgoliaSearchCore
[gatsby-fallfish-tenkara-blog]/[algoliasearch]/src/AlgoliaSearchCore.js:50:11
- AlgoliaSearch.js:11 AlgoliaSearchNodeJS.AlgoliaSearch
[gatsby-fallfish-tenkara-blog]/[algoliasearch]/src/AlgoliaSearch.js:11:21
- AlgoliaSearchServer.js:17 AlgoliaSearchNodeJS.AlgoliaSearchServer
[gatsby-fallfish-tenkara-blog]/[algoliasearch]/src/server/builds/AlgoliaSearchServer.js:17:17
- node.js:83 new AlgoliaSearchNodeJS
[gatsby-fallfish-tenkara-blog]/[algoliasearch]/src/server/builds/node.js:83:23
- node.js:68 algoliasearch
[gatsby-fallfish-tenkara-blog]/[algoliasearch]/src/server/builds/node.js:68:10
- gatsby-node.js:46 Object.exports.onPostBuild
[gatsby-fallfish-tenkara-blog]/[gatsby-plugin-algolia]/gatsby-node.js:46:18
- api-runner-node.js:485 runAPI
[gatsby-fallfish-tenkara-blog]/[gatsby]/src/utils/api-runner-node.js:485:22
- api-runner-node.js:636 Promise.catch.decorateEvent.pluginName
[gatsby-fallfish-tenkara-blog]/[gatsby]/src/utils/api-runner-node.js:636:13
- debuggability.js:384 Promise._execute
[gatsby-fallfish-tenkara-blog]/[bluebird]/js/release/debuggability.js:384:9
- promise.js:518 Promise._resolveFromExecutor
[gatsby-fallfish-tenkara-blog]/[bluebird]/js/release/promise.js:518:18
- promise.js:103 new Promise
[gatsby-fallfish-tenkara-blog]/[bluebird]/js/release/promise.js:103:10
- api-runner-node.js:634
[gatsby-fallfish-tenkara-blog]/[gatsby]/src/utils/api-runner-node.js:634:16
- util.js:16 tryCatcher
[gatsby-fallfish-tenkara-blog]/[bluebird]/js/release/util.js:16:23
- reduce.js:166 Object.gotValue
[gatsby-fallfish-tenkara-blog]/[bluebird]/js/release/reduce.js:166:18
- reduce.js:155 Object.gotAccum
[gatsby-fallfish-tenkara-blog]/[bluebird]/js/release/reduce.js:155:25
- util.js:16 Object.tryCatcher
[gatsby-fallfish-tenkara-blog]/[bluebird]/js/release/util.js:16:23
not finished onPostBuild - 0.194s
I have the following in my .env.production
file:
GATSBY_ALGOLIA_APP_ID=xxxx
GATSBY_ALGOLIA_SEARCH_KEY=xxxxxx
GATSBY_ALGOLIA_INDEX_NAME=xxxx
ALGOLIA_ADMIN_KEY=xxxxxx
I have also added the above fields to Netlify -> Site settings -> Build & Deploy (but without the prepended GATSBY_)
I read over the Gatsby docs re: @lettie16 suggestion and I believe I have implemented Gatsby Enviroment Variables correctly...
from gatsby-plugin-algolia.
what about your Gatsby config @Isaac-Tait ?
from gatsby-plugin-algolia.
require("dotenv").config({
path: `.env.${process.env.NODE_ENV}`,
})
const BlogQuery = `
{
{
allMarkdownRemark {
nodes {
frontmatter {
description
tags
title
}
internal {
content
}
}
}
}
`;
const queries = [
{
query: BlogQuery,
transformer: ({ data }) => data.allMarkdownRemark.nodes, // optional
settings: {
// optional, any index settings
// Note: by supplying settings, you will overwrite all existing settings on the index
},
matchFields: ['slug', 'modified'],
}
]
<the rest of my config>
{
// This plugin must be placed last in your list of plugins to ensure that it can query all the GraphQL data
resolve: `gatsby-plugin-algolia`,
options: {
appId: process.env.ALGOLIA_APP_ID,
// Use Admin API key without GATSBY_ prefix, so that the key isn't exposed in the application
// Tip: use Search API key with GATSBY_ prefix to access the service from within components
apiKey: process.env.ALGOLIA_API_KEY,
indexName: process.env.ALGOLIA_INDEX_NAME, // for all queries
queries,
chunkSize: 10000, // default: 1000
settings: {
// optional, any index settings
// Note: by supplying settings, you will overwrite all existing settings on the index
},
enablePartialUpdates: true, // default: false
matchFields: ['slug', 'modified'], // Array<String> default: ['modified']
concurrentQueries: false, // default: true
skipIndexing: false, // default: false, useful for e.g. preview deploys or local development
},
},
from gatsby-plugin-algolia.
@lettie16 In my .env.production file I have the Algolia variable pre-pended with GATSBY_. In the gatsby-config.js
file though I have left the variables as is from the Algolia Gatsby plugin README.md doc
The plugin docs also specify that the:
Use Admin API key without GATSBY_ prefix, so that the key isn't exposed in the application
Are you saying that you changed the apiKey
and the indexName
from:
apiKey: process.env.ALGOLIA_API_KEY,
indexName: process.env.ALGOLIA_INDEX_NAME,
to
apiKey: process.env.GATSBY_ALGOLIA_API_KEY,
indexName: process.env.GATSBY_ALGOLIA_INDEX_NAME,
???
Thank you for your response. I am not sure what I am doing wrong to cause this or if it is a bug...
from gatsby-plugin-algolia.
you should leave the process variables the same in the config, without GATSBY (since otherwise you leak them to the frontend), but you need to make sure that they're set in netlify too, in there I only see the GATSBY_ prefixed ones in your post @Isaac-Tait
from gatsby-plugin-algolia.
@Haroenv This is what I have in Netlify...
Just to clarify I have not pre-pended the variables with GATSBY in gatsby.config
, just the .env.production
file...
Here is a link to my repo if it may be helpful
from gatsby-plugin-algolia.
I'm not sure what's going on without looking at the exact values you are passing into the plugin are by console.logging in the Gatsby config you're using on netlify. Unfortunately this is very hard to debug without having access to the configurations
from gatsby-plugin-algolia.
Thank you for walking me through this @Haroenv... Looking at my Deploy Logs on Netlify I am getting this:
7:06:55 AM: [Algolia] 1 queries to index
7:06:55 AM: [Algolia] Running 1 query for index ****...
7:06:55 AM: error failed to index to Algolia
7:06:55 AM:
7:06:55 AM:
7:06:55 AM: GraphQLError: Syntax Error: Expected Name, found {
7:06:55 AM:
7:06:55 AM: - graphql-runner.ts:88 GraphQLRunner.parse
7:06:55 AM: [repo]/[gatsby]/src/query/graphql-runner.ts:88:34
7:06:55 AM:
7:06:55 AM: - graphql-runner.ts:161 GraphQLRunner.query
7:06:55 AM: [repo]/[gatsby]/src/query/graphql-runner.ts:161:27
7:06:55 AM:
7:06:55 AM: - create-graphql-runner.ts:59
7:06:55 AM: [repo]/[gatsby]/src/bootstrap/create-graphql-runner.ts:59:8
7:06:55 AM:
7:06:55 AM: - gatsby-node.js:381 getObjectsMapByQuery
7:06:55 AM: [repo]/[gatsby-plugin-algolia]/gatsby-node.js:381:24
7:06:55 AM:
7:06:55 AM:
7:06:55 AM: not finished onPostBuild - 0.352s
7:06:55 AM: npm ERR! code ELIFECYCLE
7:06:55 AM: npm ERR! errno 1
7:06:55 AM: npm ERR! [email protected] build: `gatsby build`
7:06:55 AM: npm ERR! Exit status 1
7:06:55 AM: npm ERR!
7:06:55 AM: npm ERR! Failed at the [email protected] build script.
7:06:55 AM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
7:06:55 AM: npm ERR! A complete log of this run can be found in:
7:06:55 AM: npm ERR! /opt/buildhome/.npm/_logs/2021-03-04T15_06_55_822Z-debug.log
7:06:55 AM:
7:06:55 AM: ────────────────────────────────────────────────────────────────
7:06:55 AM: "build.command" failed
7:06:55 AM: ────────────────────────────────────────────────────────────────
7:06:55 AM:
7:06:55 AM: Error message
7:06:55 AM: Command failed with exit code 1: npm run build
7:06:55 AM:
7:06:55 AM: Error location
7:06:55 AM: In Build command from Netlify app:
7:06:55 AM: npm run build
7:06:55 AM:
7:06:55 AM: Resolved config
7:06:55 AM: build:
7:06:55 AM: command: npm run build
7:06:55 AM: commandOrigin: ui
7:06:55 AM: environment:
7:06:55 AM: - ALGOLIA_ADMIN_KEY
7:06:55 AM: - ALGOLIA_API_KEY
7:06:55 AM: - ALGOLIA_APP_ID
7:06:55 AM: - ALGOLIA_BASE_URL
7:06:55 AM: - ALGOLIA_INDEX_NAME
7:06:55 AM: publish: /opt/build/repo/public
7:06:55 AM: plugins:
7:06:55 AM: - inputs: {}
7:06:55 AM: origin: ui
7:06:55 AM: package: '@algolia/netlify-plugin-crawler'
7:06:56 AM: Caching artifacts
Would this help at all?
from gatsby-plugin-algolia.
I removed the prepended GATSBY_ from the variables in my .env.production
file. Now the error is gone but the onPostBuild
is failing... When I put GATSBY_
before the variable names the error returns:
ERROR #11321 PLUGIN
"gatsby-plugin-algolia" threw an error while running the onPostBuild lifecycle:
Please provide an application ID. Usage: algoliasearch(applicationID, apiKey, opts)
44 | }
45 |
> 46 | const client = algoliasearch(appId, apiKey);
| ^
47 |
48 | setStatus(activity, `${queries.length} queries to index`);
49 |
File: node_modules/gatsby-plugin-algolia/gatsby-node.js:46:18
AlgoliaSearchError: Please provide an application ID. Usage: algoliasearch(applicationID, apiKey, opts)
For experimentation sake I changed the gatsby.config
file to (even though the docs say not to):
{
resolve: `gatsby-plugin-algolia`,
options: {
appId: process.env.GATSBY_ALGOLIA_APP_ID,
apiKey: process.env.GATSBY_ALGOLIA_SEARCH_KEY,
indexName: process.env.GATSBY_ALGOLIA_INDEX_NAME,
queries,
chunkSize: 1000,
},
enablePartialUpdates: true,
matchFields: ['slug', 'modified'],
},
and the onPostBuild
still failed.
I have reverted to removing all GATSBY_
prependings from the .env.production
and gatsby-config
files.
from gatsby-plugin-algolia.
I found this closed issue and tried "adding the modified
field into both queries and adding the matchFields
setting to the plugin settings passing modified in the array." and that did not resolve the onPostBuild
failure.
I have all the variables found in the .env.production
listed within Netlify -> Build & deploy -> Variables (which I have read if those are missing can cause the onPostBuild
to fail...).
from gatsby-plugin-algolia.
Hi,
We are currently running in the same problem with the Algolia and Netlify build. Some of the builds are failing while the some are working properly. I'm wondering if anyone has a pointer how to resolve this. The error log is:
11:58:29 PM: Please provide an application ID. Usage: algoliasearch(applicationID, apiKey, opts)
11:58:29 PM: 45 | }
11:58:29 PM: 46 |
11:58:29 PM: > 47 | const client = algoliasearch(appId, apiKey, { timeout: 30_000 });
11:58:29 PM: | ^
11:58:29 PM: 48 |
11:58:29 PM: 49 | setStatus(activity, `${queries.length} queries to index`);
11:58:29 PM: 50 |
11:58:29 PM:
11:58:29 PM:
11:58:29 PM: AlgoliaSearchError: Please provide an application ID. Usage: algoliasearch(app licationID, apiKey, opts)
11:58:29 PM:
11:58:29 PM: - AlgoliaSearchCore.js:50 AlgoliaSearchNodeJS.AlgoliaSearchCore
11:58:29 PM: [repo]/[gatsby-plugin-algolia]/[algoliasearch]/src/AlgoliaSearchCore.js:50:1 1
11:58:29 PM:
11:58:29 PM: - AlgoliaSearch.js:11 AlgoliaSearchNodeJS.AlgoliaSearch
11:58:29 PM: [repo]/[gatsby-plugin-algolia]/[algoliasearch]/src/AlgoliaSearch.js:11:21
11:58:29 PM:
11:58:29 PM: - AlgoliaSearchServer.js:17 AlgoliaSearchNodeJS.AlgoliaSearchServer
11:58:29 PM: [repo]/[gatsby-plugin-algolia]/[algoliasearch]/src/server/builds/AlgoliaSear chServer.js:17:17
11:58:29 PM:
11:58:29 PM: - node.js:83 new AlgoliaSearchNodeJS
11:58:29 PM: [repo]/[gatsby-plugin-algolia]/[algoliasearch]/src/server/builds/node.js:83: 23
11:58:29 PM:
11:58:29 PM: - node.js:68 algoliasearch
11:58:29 PM: [repo]/[gatsby-plugin-algolia]/[algoliasearch]/src/server/builds/node.js:68: 10
11:58:29 PM:
11:58:29 PM: - gatsby-node.js:47 Object.exports.onPostBuild
11:58:29 PM: [repo]/[gatsby-plugin-algolia]/gatsby-node.js:47:18
11:58:29 PM:
11:58:29 PM: - api-runner-node.js:434 runAPI
11:58:29 PM: [repo]/[gatsby]/src/utils/api-runner-node.js:434:22
11:58:29 PM:
11:58:29 PM: - api-runner-node.js:585 Promise.catch.decorateEvent.pluginName
11:58:29 PM: [repo]/[gatsby]/src/utils/api-runner-node.js:585:13
11:58:29 PM:
11:58:29 PM: - debuggability.js:384 Promise._execute
11:58:29 PM: [repo]/[bluebird]/js/release/debuggability.js:384:9
11:58:29 PM:
11:58:29 PM: - promise.js:518 Promise._resolveFromExecutor
11:58:29 PM: [repo]/[bluebird]/js/release/promise.js:518:18
11:58:29 PM:
11:58:29 PM: - promise.js:103 new Promise
11:58:29 PM: [repo]/[bluebird]/js/release/promise.js:103:10
11:58:29 PM:
11:58:29 PM: - api-runner-node.js:583
11:58:29 PM: [repo]/[gatsby]/src/utils/api-runner-node.js:583:16
11:58:29 PM:
11:58:29 PM: - util.js:16 tryCatcher
11:58:29 PM: [repo]/[bluebird]/js/release/util.js:16:23
11:58:29 PM:
11:58:29 PM: - reduce.js:166 Object.gotValue
11:58:29 PM: [repo]/[bluebird]/js/release/reduce.js:166:18
11:58:29 PM:
11:58:29 PM: - reduce.js:155 Object.gotAccum
11:58:29 PM: [repo]/[bluebird]/js/release/reduce.js:155:25
11:58:29 PM:
11:58:29 PM: - util.js:16 Object.tryCatcher
11:58:29 PM: [repo]/[bluebird]/js/release/util.js:16:23
11:58:29 PM:
11:58:29 PM:
11:58:29 PM: not finished onPostBuild - 0.166s
11:58:29 PM: not finished index to Algolia - 0.138s
11:58:29 PM:
11:58:29 PM: ────────────────────────────────────────────────────────────────
11:58:29 PM: "build.command" failed
11:58:29 PM: ────────────────────────────────────────────────────────────────
11:58:29 PM:
11:58:29 PM: Error message
11:58:29 PM: Command failed with exit code 1: gatsby build
11:58:29 PM:
11:58:29 PM: Error location
11:58:29 PM: In Build command from Netlify app:
11:58:29 PM: gatsby build
11:58:29 PM:
11:58:29 PM: Resolved config
11:58:29 PM: build:
11:58:29 PM: command: gatsby build
11:58:29 PM: commandOrigin: ui
11:58:29 PM: environment:
11:58:29 PM: - REVIEW_ID
11:58:29 PM: publish: /opt/build/repo/public
11:58:30 PM: Caching artifacts
from gatsby-plugin-algolia.
If you are building with Gatsby @Kn99HN I had the same error when I prepended the .env
variables with GATSBY_
. When I removed it the error cleared up... If it may be helpful, I blogged about it here.
from gatsby-plugin-algolia.
Related Issues (20)
- Question re: Algolia Search HOT 6
- Unreachable hosts Error HOT 6
- Algolia transformer returns nulls for images that are correctly displayed in built site HOT 1
- Support for Gatsby 5 HOT 2
- Gatsby 4 build broken gatsby-plugin-algolia v1.0.0 HOT 2
- failed to index to Algolia Cannot read properties of undefined (reading 'contentDigest') HOT 3
- Plugin breaking in Gatsby 5 HOT 5
- JavaScript heap out of memory HOT 5
- Add indexName to the gatsby cache key HOT 4
- Why partial partial update is no more optional ? HOT 6
- Enrich your records with Google Analytics data HOT 1
- Request for skipIndexing Option to Avoid Unwanted API Access During CI Builds HOT 2
- Extracting chunks of long text as its own record HOT 2
- Adding headers to graphql query HOT 3
- Error: cannot apply the batch operation on a replica index
- Plugin is deleting Sanity document from index if edited. HOT 3
- Adding new data to existing records is ignored HOT 3
- Gatsby internal.contentDigest is a poor source for deciding whether content needs to be updated HOT 6
- Do we still need the MatchFields and enablePartialUpdate options in config? HOT 2
- Partially update not updating existing object in index HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gatsby-plugin-algolia.