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.

Is create-react-native-app supported?

See original GitHub issue

I’m attempting to use this plugin with a create-react-native-app (CRNA) but when importing a .graphql file into a typescript file, I’m seeing the error:

Unable to resolve ./query.graphql" from "src/Welcome/index.tsx`: The module `./query.graphql` could not be found.

I noticed the babel-plugin-inline-import-graphql-ast package, but it works with react-app-rewired which is for create-react-app and not create-react-native-app.

Any ideas?

Here’s my .babelrc

{
  "plugins": ["import-graphql"],
  "presets": ["babel-preset-expo"],
  "env": {
    "development": {
      "plugins": [
        "transform-react-jsx-source"
      ]
    }
  }
}

and package.json

{
  "name": "tortuga",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "@types/jest": "^22.2.3",
    "@types/react": "^16.3.14",
    "@types/react-native": "^0.55.16",
    "@types/react-test-renderer": "^16.0.1",
    "apollo-codegen": "^0.19.1",
    "babel-plugin-import-graphql": "^2.4.4",
    "react-app-rewired": "^1.5.2",
    "react-native-scripts": "1.14.0",
    "react-native-typescript-transformer": "^1.2.9",
    "tslint-react": "^3.6.0",
    "typescript": "^2.8.3"
  },
  "main": "./src/index.js",
  "scripts": {
    "start": "react-native-scripts start",
    "eject": "react-native-scripts eject",
    "android": "react-native-scripts android",
    "ios": "react-native-scripts ios",
    "test": "jest",
    "generate-schema": "apollo-codegen introspect-schema http://localhost:8080/graphql --output lib/schema.json"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "apollo-boost": "^0.1.7",
    "expo": "^27.0.2",
    "graphql": "^0.13.2",
    "react": "16.4.0",
    "react-apollo": "^2.1.4",
    "react-native": "~0.55.2",
    "tslint": "^5.10.0"
  }
}

Issue Analytics

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

github_iconTop GitHub Comments

6reactions
pm-devcommented, Jun 4, 2018

Changing the module compiler option in tsconfig.json from commonjs to es2015 allowed the js bundle to build.

My IDE was still reporting an error because it couldn’t find the module for my .graphql file, which was fixed by your suggestion of adding fileExtensions.d.ts with

declare module '*.graphql';

Thanks for your help debugging.

1reaction
detrohuttcommented, Jun 4, 2018

Oh it sounds like just a type issue. What i did was make a types folder in my project root with a fileExtensions.d.ts file like this in it:

declare module '*.graphql';

And then add that folder to my typeRoots in tsconfig.json:

"typeRoots": ["./types/", "./node_modules/@types/", "./**/node_modules/@types/"]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing Create React Native App
With Create React Native App, there's no need to use Xcode or Android Studio, and you can develop for your iOS device using...
Read more >
expo/create-react-native-app - GitHub
Expo Client supports running any project that doesn't have custom native modules added.
Read more >
create-react-native-app - npm
Start using create-react-native-app in your project by running `npm i create-react-native-app`. There are 5 other projects in the npm ...
Read more >
How to create React Native App for Android, iOS and Web ...
Step 1: Init a React Native Application: · Step 2: Run this new app in Android (optional) · Step 3: Web Setup.
Read more >
The complete guide to React Native for Web - LogRocket Blog
Yes ! With React Native for Web, developers can write a single React Native application that can run natively on Android and iOS,...
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