aidenybai / million

Optimize React performance and make your React 70% faster in minutes, not months.
https://million.dev
MIT License
15.89k stars 558 forks source link

Issue with using .graphql files with graphql-tag in Next.js #1002

Closed jagadish-k closed 2 months ago

jagadish-k commented 3 months ago

What version of million are you using?

0.0.73

Are you using an SSR adapter? If so, which one?

No

What package manager are you using?

npm

What operating system are you using?

Mac

What browser are you using?

Chrome

Describe the Bug

I added Millionlint into my Next.js application that uses graphql with apollo client. Whenever I access a component/page that imports a .graphql file, I get the error

./src/graphql/star-wars-query.graphql
Module parse failed: Unexpected token (1:6)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> query AllFilmsQuery {
|   allFilms {
|     films {

Changing this line in next.config.mjs

module.exports = MillionLint.next()(nextConfig);

back to the original

module.exports = nextConfig;

restores the functionality of the application. It works as expected when I access pages that do not need the graphql files for fetching any data.

Complete next.config.js

import MillionLint from '@million/lint';
/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  webpack: (config, options) => {
    config.module.rules.push({
      test: /\.(graphql|gql)$/,
      exclude: /node_modules/,
      loader: 'graphql-tag/loader'
    });
    return config;
  }
};
export default MillionLint.next()(nextConfig);

What's the expected result?

The modified config should build on top of the existing config for the application. The configured loader for .graphql files should work.

Link to Minimal Reproducible Example

https://github.com/jagadish-k/nextjs-graphql-millionlint

Participation

github-actions[bot] commented 3 months ago

Thanks for opening this issue! A maintainer will review it soon.

tobySolutions commented 3 months ago

Thank you for sharing this @jagadish-k, I'll inform the team of this. it's definitely a weird error.

github-actions[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days.

Saul-BT commented 2 months ago

I have the same problem

jagadish-k commented 3 weeks ago

out of curiosity, was this fixed ?

bmarcot commented 1 day ago

Facing the issue as well. Loader won't load gql modules.

"graphql": "^16.9.0",
"graphql-tag": "^2.12.6",
"next": "14.2.4",