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.

babel 7 configuration format

See original GitHub issue

Hi there,

I’m trying to bumble my way through to having a working babel7-based setup but there seems to be something wrong the moment i pull in “babel-plugin-inline-import-graphql-ast”

Here is my babel.config.js (this is now the babel7 method to specify a project-wide babel config, in lieu of .babelrc):

// https://github.com/babel/babel/pull/7358#issuecomment-388311941
module.exports = {
  overrides: [{
    test: '*',
    presets: [
      ['@babel/preset-env', {'node': 'current'}],
    ],
    plugins: [
      [
        "babel-plugin-inline-import",
        {
          extensions: [
            ".css"
          ]
        }
      ],
      "babel-plugin-inline-import-graphql-ast"
    ],
    env: {
      development: {
        presets: [
          "next/babel",
        ]
      },
      production: {
        presets: [
          [
            "next/babel",
            {
              ["preset-env"]: {
                targets: {
                  browsers: "> 5%"
                }
              }
            }
          ]
        ]
      },
      test: {
        presets: [
          [
            "next/babel",
            {
              ["preset-env"]: {
                modules: true
              }
            }
          ]
        ]
      }
    }
  }],
  ignore: [
    "/*.plain/"
  ]
}

Example usage of the graphql inlining:

# ---- https://github.com/apollographql/graphql-tag
#import "./Category3Fragment.graphql"
#import "./Category2Fragment.graphql"
#import "./Category1Fragment.graphql"


query Category1(
  $canonicalised_name: String,
  $category1__canonicalised_name: String,
) {
  category1 (
    canonicalised_name: $canonicalised_name,
    category1__canonicalised_name: $category1__canonicalised_name,
  ) {
      ...Category1Fragment
  }
}

Error text:

Module build failed: Error: Configuration contains explicit test/include/exclude checks, but no filename was passed to Babel
    at configFieldIsApplicable (/Users/matt/dev/partridge/frontend/node_modules/@babel/core/lib/config/config-chain.js:401:11)
    at configIsApplicable (/Users/matt/dev/partridge/frontend/node_modules/@babel/core/lib/config/config-chain.js:396:41)
    at forEach (/Users/matt/dev/partridge/frontend/node_modules/@babel/core/lib/config/config-chain.js:242:13)
    at Array.forEach (<anonymous>)
    at /Users/matt/dev/partridge/frontend/node_modules/@babel/core/lib/config/config-chain.js:239:42
    at buildRootChain (/Users/matt/dev/partridge/frontend/node_modules/@babel/core/lib/config/config-chain.js:90:20)
    at loadPrivatePartialConfig (/Users/matt/dev/partridge/frontend/node_modules/@babel/core/lib/config/partial.js:51:55)
    at loadFullConfig (/Users/matt/dev/partridge/frontend/node_modules/@babel/core/lib/config/full.js:43:39)
    at transformSync (/Users/matt/dev/partridge/frontend/node_modules/@babel/core/lib/transform-sync.js:15:38)
    at buildVariableAST (/Users/matt/dev/partridge/frontend/node_modules/babel-plugin-inline-import-graphql-ast/build/index.js:87:58)
    at /Users/matt/dev/partridge/frontend/node_modules/babel-plugin-inline-import-graphql-ast/build/index.js:72:26
    at Array.map (<anonymous>)
    at buildReplacements (/Users/matt/dev/partridge/frontend/node_modules/babel-plugin-inline-import-graphql-ast/build/index.js:65:31)
    at PluginPass.exit (/Users/matt/dev/partridge/frontend/node_modules/babel-plugin-inline-import-graphql-ast/build/index.js:59:34)
    at newFn (/Users/matt/dev/partridge/frontend/node_modules/@babel/core/node_modules/@babel/traverse/lib/visitors.js:237:21)
    at NodePath._call (/Users/matt/dev/partridge/frontend/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:65:20)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
loganfsmythcommented, May 16, 2018

Nope! It’s a brand new feature in Babel 7, so I can’t imagine anyone would be relying on it, and your code already skips reading .babelrc files since the JS snippet doesn’t have a filename.

2reactions
loganfsmythcommented, May 16, 2018

This line https://github.com/detrohutt/babel-plugin-inline-import-graphql-ast/blob/678284600731bc77b632766f969a6033d9304700/plugin/index.js#L54 will attempt to load the user’s babel.config.js file too, because it is not passing configFile: false when calling transformSync.

My recommendation would be to drop the usage of transformSync entirely.

export default ({ types: t }) => ({

should expand to

export default ({ types: t, template }) => ({

and then

function buildVariableAST(graphqlAST, importName) {
  const { ast } = transformSync(`var ${importName} = ${JSON.stringify(graphqlAST)}`, {
    ast: true
  })
  return ast.program.body[0]
}

can be

const buildAst = template(`var IMPORT_NAME = AST;`);
function buildVariableAST(graphqlAST, importName) {
  return buildAst({ 
    IMPORT_NAME: t.identifier(importName), 
    AST: t.valueToNode(graphqlAST),
  });
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Config Files - Babel.js
Babel can be configured using any file extension natively supported by Node.js, as mentioned in Configuration File Types section: babel.config.json and .babelrc ...
Read more >
Babel 7: Configuration, Preset, and Plugin Usage
Although structurally different from the original file, it is code that will work in current browsers and the Node.js platform. @ babel /...
Read more >
Configuring Babel 7 - YouTube
How Babel 7 configuration works.Repo: https://github.com/kentcdodds/babel- config -exampleDocs: ...
Read more >
The New Babel 7 Config - Maria D. Campbell
ended up that I had to ; change my ; Babel 7 configuration file from .babelrc to babel.config.js . ; Babel 7 ;...
Read more >
Working with Babel 7 and Webpack | The Basement
We will need a couple of different things to set up Babel: a couple of npm-packages , a .babelrc -file and a .browserslistrc...
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