detrohutt / react-app-rewire-inline-import-graphql-ast

Add the inline-import-graphql-ast Babel plugin to your create-react-app app via react-app-rewired
MIT License
17 stars 2 forks source link

Usage with create-react-app 2.0+ #9

Closed Matmo10 closed 5 years ago

Matmo10 commented 5 years ago

When you try to use this with create-react-app@2.14, this error happens:

The "injectBabelPlugin" helper has been deprecated as of v2.0. You can use customize-cra plugins in replacement - https://github.com/arackaf/customize-cra#available-plugins
error Command failed with exit code 1.

So I tried using customize-cra like it suggests, by changing my config-overrides.js to the following:

const { override, addBabelPlugin } = require("customize-cra");

module.exports = override(
    addBabelPlugin(
        ["babel-plugin-import-graphql", {nodePath: process.env.NODE_PATH}]
    )
);

But it doesn't seem to work since I see these errors:

TypeScript error: Cannot find module 'src/pages/something/SomeMutation.mutation.graphql'.  TS2307

  > import * as SomeGraphql from 'src/pages/something/SomeMutation.mutation.graphql';

The apollo docs recommend this package, so just curious if you had any advice for create-react-app 2.0+. Thanks!

gen1321 commented 5 years ago

I was able to get it working with ur solution. dunno maybe u forgot .babelrc or something

Matmo10 commented 5 years ago

My bad, I think I just needed to add some additional typings for graphql files so tsc would even consider loading the file, so it was a typescript issue.