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.

Using with Next.js

See original GitHub issue

Using Next.JS/examples/with-apollo (Canary branch) as a demonstration project, I’m attempting to move the graphql ‘allPosts’ query to an external .gql file.

Having followed the instructions to implement this plugin, I’m getting an error that seems to suggest JSX processing is not happening:

error  in ./pages?entry
Syntax Error: Unexpected token (8:2)
   6 | 
   7 | export default withData(() => (
>  8 |   <App>
     |   ^

I am using latest versions of node, babel, next, etc. Should this work? Have I made an error somewhere?

The demonstration project can be found at https://github.com/gihrig/next-apollo-gql

OS: Mac 10.11.6 Node: 8.9.4 React: 16.2.0 Next: latest

Any help sincerely appreciated 😃

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
gihrigcommented, Jan 27, 2018

@detrohutt Your assessment is spot on! All works as expected now. 💯

I didn’t realize that .babelrc overrode Next’s internal config. I assumed it extended it.

Thanks for taking the time to help me over a noob speed bump. 😄

1reaction
detrohuttcommented, Jan 26, 2018

@gihrig Sorry it took me so long to get around to this. Thanks for trying my package and thanks for taking the time to provide the steps you took.

I wrote the README.md to be generic for anyone using the package, not just Next.js users. My example .babelrc is generic, so if you were going to use it for Next.js it’d need to include their preset as described in the Next.js README.

I followed your directions to the point where I got the error, then used this .babelrc:

{
  "presets": ["next/babel"],
  "plugins": ["babel-plugin-inline-import-graphql-ast"]
}

That fixed the error and I converted a single gql query to it’s own file and imported it to make sure it worked as expected, which it did. I don’t expect you’ll have any issues once you’ve added that top line to your .babelrc

As a side note, make sure you check out the Caveats section of my README because you’ll probably need to change your npm scripts in package.json to prepend them as described… i.e.

  "scripts": {
    "dev": "rm -rf node_modules/.cache && next",
    "build": "rm -rf node_modules/.cache && next build",
    "start": "rm -rf node_modules/.cache && next start"
  },

and then you’ll have to kill and rerun the command (i.e. yarn dev) each time you make a change to a .gql/.graphql file. Otherwise, the changes you make won’t be reflected in the running program, unfortunately.

I’m going to close this issue for now, but if you have any more problems you can reopen it. Good luck, thanks again, and enjoy the package!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started | Next.js
If you're new to Next.js, we recommend starting with the learn course. The interactive course with quizzes will guide you through everything you...
Read more >
Create a Next.js App | Learn Next.js
Next.js: The React Framework · An intuitive page-based routing system (with support for dynamic routes) · Pre-rendering, both static generation (SSG) and server- ......
Read more >
Basic Features: Pages - Next.js
In Next.js, a page is a React Component exported from a .js , .jsx , .ts , or .tsx file in the pages...
Read more >
Setup - Create a Next.js App
You'll be using your own text editor and terminal app for this tutorial. ... the directory you'd like to create the app in,...
Read more >
What is Next.js?
Next.js is a React framework that gives you building blocks to create web applications. By framework, we mean Next.js handles the tooling and...
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