apollographql / apollographql/apollo-tooling
Syntax Error: Unexpected <EOF>
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 460
- PR merge metrics
- No merged PRs in 30d
Description
**Intended outcome:**
When running:
```
npx apollo client:codegen --target=typescript --globalTypesFile=./src/__generated__/globalTypes.ts
```
I would expect to get types generated.
**Actual outcome:**
```
yarn run v1.22.4
$ npx apollo client:codegen --target=typescript --globalTypesFile=./src/__generated__/globalTypes.ts
✔ Loading Apollo Project
✖ Generating query files with 'typescript' target
→ Syntax error in file:///Users/chris/Apps/ReactNative/Tracker/node_modules/graphql-tag/loader.js: Syntax Error: Unexpected .
Error: Syntax error in file:///Users/chris/Apps/ReactNative/Tracker/node_modules/graphql-tag/loader.js: Syntax Error: Unexpected .
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```
**How to reproduce the issue:**
Not able to share the repo, but it's a fresh React Native app with the dependencies listed below. I tried running using `apollo@latest` and `apollo@2.30.2`. Also tried clearing the `node_modules` folder and reinstalling to no avail.
`apollo.config.js`:
```
module.exports = {
client: {
tagName: 'gql',
includes: ['./**/!(*.test).{ts,tsx,js,jsx}'],
service: {
name: 'Tracker API',
url: 'http://localhost:5001',
},
},
}
```
**Versions**
```
"dependencies": {
"@apollo/client": "^3.1.4",
"date-fns": "^2.16.1",
"graphql-tag": "^2.11.0", // This was added as an attempt to fix - also tried the previosu version
"react": "16.13.1",
"react-native": "0.63.2",
"react-native-navigation": "^6.12.2",
"react-native-navigation-hooks": "^6.1.0"
},
"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/runtime": "^7.8.4",
"@react-native-community/eslint-config": "^1.1.0",
"@types/jest": "^25.2.3",
"@types/react-native": "^0.63.2",
"@types/react-test-renderer": "^16.9.2",
"@typescript-eslint/eslint-plugin": "^2.27.0",
"@typescript-eslint/parser": "^2.27.0",
"babel-jest": "^25.1.0",
"babel-plugin-module-resolver": "^4.0.0",
"babel-plugin-transform-remove-console": "^6.9.4",
"eslint": "^6.5.1",
"jest": "^25.1.0",
"metro-react-native-babel-preset": "^0.59.0",
"prettier": "^2.1.1",
"react-test-renderer": "16.13.1",
"typescript": "^3.8.3"
},
```
UPDATE: simplifying `apollo.config.js` to the following seems to fix:
```
module.exports = {
client: {
service: {
name: 'Tracker API',
url: 'http://localhost:5001',
},
},
}
```
It looks like it's the `includes`. Changing the line to the following fixes:
```
includes: ['./src/**/!(*.test).{ts,tsx,js,jsx}'],
```
Not sure if this is an issue or not. It happens that in my case I don't need to include anything outside of the `src` folder. Could it be a lack of `excludes`, and so it's scanning the node modules folder? This hasn't happened on previous projects.
Contributor guide
Research direction
The reported command is configured in apollo.config.js, and the error points to node_modules/graphql-tag/loader.js. Start by comparing the working src-scoped includes glob with the failing repository-wide glob and check whether node_modules is scanned. Done means reproducing code generation with the intended includes behavior without the Unexpected error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, react-native, typescript
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100