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.

Problem with babel config

See original GitHub issue

this is my babel.config.js

module.exports = {
  presets: [
    '@babel/preset-react',
    '@babel/preset-flow',
    [
      '@babel/preset-env',
      {
        modules: false,
      },
    ],
  ],
  plugins: [
    'react-hot-loader/babel',
    'loadable-components/babel',
    'babel-plugin-styled-components',
    [
      'relay',
      {
        schema: 'data/schema.json',
      },
    ],
    'material-ui',
    'lodash',
    '@babel/plugin-proposal-object-rest-spread',
    '@babel/plugin-proposal-class-properties',
    '@babel/plugin-proposal-export-default-from',
    '@babel/plugin-proposal-export-namespace-from',
  ],
  overrides: [
    {
      test: ['./src/**/*.ts'],
      presets: [
        '@babel/preset-typescript',
        [
          '@babel/preset-env',
          {
            modules: false,
          },
        ],
        '@babel/preset-react',
      ],
    },
  ],
  env: {
    test: {
      presets: ['@babel/preset-flow', '@babel/preset-env', '@babel/preset-react'],
      plugins: [
        '@babel/plugin-transform-runtime',
        'dynamic-import-node',
        '@babel/plugin-syntax-dynamic-import',
        '@babel/plugin-proposal-object-rest-spread',
        '@babel/plugin-proposal-class-properties',
        '@babel/plugin-proposal-export-default-from',
        '@babel/plugin-proposal-export-namespace-from',
      ],
    },
  },
};

it throws the following error

Error: Configuration contains string/RegExp pattern, but no filename was passed to Babel

because of overrides syntax that needs to accept a filename

I’ve solved this passing filename to babel transform:

const code = babel.transformSync(preprocess(cmd), {
    presets: [...]
    plugins: [...]
    filename: './babel.config.js', // hacky to make overrides works
  }).code;

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
afenton90commented, Oct 25, 2018

I narrowed this down to having a pattern in something like an ignore field for example a config file like this babel.config.js caused the error:

module.exports = {
  plugins: [...],
  presets: [...],
  ignore: ['**/public/*.js']
};

For me I realised I didn’t need this particular ignore. I couldn’t find the magic combination of options for babel.transform to get it to work. Hope that gets this issue a step closer.

1reaction
milesjcommented, Oct 11, 2018

Running into this also now. Is babel/ts transpilation really necessary? This definitely feels like something that shouldn’t exist.

Read more comments on GitHub >

github_iconTop Results From Across the Web

npx babel not reading configuration from babel.config.js
When running npx babel index.js from the command line, I was hoping I would see my babel configurations being applied from babel.config.js.
Read more >
Configure Babel
Create a file called babel.config.json with the following content at the root of your project (where the package.json is). ... Check out the...
Read more >
Solving Babel issue in Ejected React Application
It throws an Unexpected token syntax error. The issue is that Babel is no longer able to understand JSX (HTML like) syntax inside...
Read more >
Babel
Storybook's webpack config by default sets up Babel for ES6 transpiling. ... part of @storybook/addon-essentials , as this currently causes issues in IE11....
Read more >
ESLint: Parsing error: No Babel config file detected ... - YouTrack
ESLint: Parsing error: No Babel config file detected (using @babel/eslint-parser) ... Hello,. Since moving from the deprecated babel-eslint to the recommended @ ...
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