Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with babel config #664

Closed
sibelius opened this issue Sep 15, 2018 · 5 comments
Closed

Problem with babel config #664

sibelius opened this issue Sep 15, 2018 · 5 comments

Comments

@sibelius
Copy link

@sibelius sibelius commented Sep 15, 2018

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;
@orta
Copy link
Member

@orta orta commented Sep 15, 2018

Interesting, we're definitely passing the filename in at transform - I wonder if it's needed for the get options beforehand?

@orta
Copy link
Member

@orta orta commented Sep 15, 2018

Maybe we need to set sourceFilename?

@milesj
Copy link

@milesj milesj commented Oct 11, 2018

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

@afenton90
Copy link

@afenton90 afenton90 commented 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.

@orta
Copy link
Member

@orta orta commented Oct 25, 2018

Maybe danger can override the ignore with something empty in the config?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants