question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

preprocessor error when querying from load function

See original GitHub issue

Other houdini queries are working just fine, but when I try querying from inside the load function in SvelteKit it throws this error below.

Error: Looks like you don't have the preprocessor enabled.
    at Module.graphql (/$houdini/runtime/index.js:21:11)
    at eval (/Users/benj/projects/preview-app/src/routes/u/[sellerUsername].svelte:69:77)
    at Generator.next (<anonymous>)
    at eval (/Users/benj/projects/preview-app/src/routes/u/[sellerUsername].svelte:59:66)
    at new Promise (<anonymous>)
    at __awaiter (/Users/benj/projects/preview-app/src/routes/u/[sellerUsername].svelte:36:9)
    at load (/Users/benj/projects/preview-app/src/routes/u/[sellerUsername].svelte:65:28)
    at load_node (file:///Users/benj/projects/preview-app/node_modules/@sveltejs/kit/dist/ssr.js:864:30)
    at respond$1 (file:///Users/benj/projects/preview-app/node_modules/@sveltejs/kit/dist/ssr.js:1136:21)
    at async render_page (file:///Users/benj/projects/preview-app/node_modules/@sveltejs/kit/dist/ssr.js:1290:20)

My svelte.config.js file:

import preprocess from 'svelte-preprocess'
import houdini from 'houdini-preprocess'
import node from '@sveltejs/adapter-node'
import path from 'path'

/** @type {import('@sveltejs/kit').Config} */
const config = {
  preprocess: [preprocess({ postcss: true }), houdini()],

  kit: {
    // hydrate the <div id="svelte"> element in src/app.html
    target: '#svelte',
    adapter: node(),
    vite: {
      resolve: {
        alias: {
          $houdini: path.resolve('.', '$houdini')
        }
      }
    }
  }
}

export default config

The load function (please let me know if I’m using this wrong):

<script lang="ts" context="module">
  import type { Load } from '@sveltejs/kit'
  import { query, graphql } from '$houdini'
  export const load: Load = async ({ page }) => {
    const username = page.params.sellerUsername
    try {
      const { data } = query(graphql`
        ... query data
      `)
      const seller = data.get_seller
      return {
        props: {
          seller
        }
      }
    } catch (err) {
      console.log(err)
      return {
        status: 400,
        error: new Error(err[0].message)
      }
    }
  }
</script>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pixelmundcommented, Aug 23, 2021

This is not how Houdini works. Houdinis preprocessor automatically transforms your query into the load function. https://github.com/AlecAivazis/houdini#what-about-load

1reaction
AlecAivaziscommented, Aug 23, 2021

Hey @ledesmablt - sorry to hear you are running into some issues.

The query function isn’t meant to be inside of a load function as you have it. The preprocessor only looks inside of the instance scripts to replace the graphql tag. The idea is that you shouldn’t have to worry about defining your load function, and threading the value to your components props - the preprocessor takes care of that for you.

Can you give me some more information about what you’re trying to accomplish?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I generate an error or warning in the C preprocessor?
To do this, click on the Project menu, select Properties..., and in the Build targets tab you can click on Release and then...
Read more >
Error while calling a function to fetch data · Issue #66 - GitHub
I have a error when trying fetching data with basic code from example: ... import { query, graphql, AllItems } from '$houdini'; //...
Read more >
SQL Preprocessor | Exasol DB Documentation
Returns whether the input string is a SQL keyword token (for example, SELECT , FROM , TABLE ). The functions isidentifier() and iskeyword()...
Read more >
PREPROCESSOR - Oracle Help Center
The PREPROCESSOR option passes the input data ( deptxt.dat ) to sed.bat . If you then select from the deptxt table, the results...
Read more >
How To Use PreProcessors In JMeter
In this tutorial, you will learn to use JMeter PreProcessor and how do PreProcessors like SampleTimeOut, UserParameter, HTMLLinkParser work.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found