detrohutt/babel-plugin-import-graphql

Fails after `npm install` (TypeError: Cannot read property 'program' of null)

oudmane opened this issue · 7 comments

I run with this issue in one of my projects.

I cloned detrohutt/babel-plugin-inline-import-graphql-ast run npm run test then faced the same issue :

 FAIL  tests/schema.test.js
  ● simple schema document › inlines as raw unparsed text'

    TypeError: Cannot read property 'program' of null

      67 |         function buildVariableAST(graphqlAST, importName) {
      68 |           const { ast } = transformSync(`var ${importName} = ${JSON.stringify(graphqlAST)}`)
    > 69 |           return ast.program.body[0]
      70 |         }
      71 |       }
      72 |     }
      
      at buildVariableAST (plugin/index.js:69:22)
      at PluginPass.exit (plugin/index.js:30:33)
      at newFn (node_modules/@babel/traverse/lib/visitors.js:223:21)
      at NodePath._call (node_modules/@babel/traverse/lib/path/context.js:64:19)
      at NodePath.call (node_modules/@babel/traverse/lib/path/context.js:38:17)
      at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:108:8)
      at TraversalContext.visitQueue (node_modules/@babel/traverse/lib/context.js:135:18)
      at TraversalContext.visitMultiple (node_modules/@babel/traverse/lib/context.js:89:17)
      at TraversalContext.visit (node_modules/@babel/traverse/lib/context.js:174:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/@babel/traverse/lib/index.js:76:17)
      at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:106:18)
      at TraversalContext.visitQueue (node_modules/@babel/traverse/lib/context.js:135:18)
      at TraversalContext.visitSingle (node_modules/@babel/traverse/lib/context.js:94:19)
      at TraversalContext.visit (node_modules/@babel/traverse/lib/context.js:176:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/@babel/traverse/lib/index.js:76:17)
      at traverse (node_modules/@babel/traverse/lib/index.js:46:12)
      at transformFile (node_modules/@babel/core/lib/transformation/index.js:108:27)
      at runSync (node_modules/@babel/core/lib/transformation/index.js:35:3)
      at transformFileSync (node_modules/@babel/core/lib/transform-file-sync.js:29:38)
      at transformWithPlugin (tests/util.js:5:10)
      at Object.<anonymous> (tests/schema.test.js:6:22)

node v8.9.3
npm v5.7.1

I was able to recreate the issue with both node v8.9.3 and node v9.8.0 along with multiple versions of npm. I don't know the cause yet but it is a problem with the way npm is resolving the dependencies. If you install the dependencies with yarn, then the tests run successfully with either npm or yarn, but if you install the dependencies with npm the tests fail with both.

After removing my yarn.lock file, the problem also occurs with yarn too, so some dependency or sub-dependency has upgraded since I released and is causing the issue. In the future I will release a package-lock.json file as well as my yarn.lock to avoid this situation. For now, I'm not sure how to fix it but if it's an option for you, you can install yarn just to install the dependencies with ( just run the command yarn) and then use npm for everything else if you want.

I did the test using yarn, It worked, I installed your package using yarn, I still get the same problem (in my project).

I believe I have it fixed. Please change your dependency on my package to "babel-plugin-inline-import-graphql-ast": "^2.3.4", remove your node_modules folder, and reinstall with npm i or yarn and everything should work.

You may need to uninstall and reinstall my package rather than just changing the version in order for the change to reflect in your package-lock.json or yarn.lock.. if that still doesn't work, you may need to remove your lock file first.

I removed node_modules lock. files and run npm install again and it worked, Thanks a lot :)

Glad it worked, thanks for reporting this bug!