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/core` `parseSync` does not handle `exclude` in config

See original GitHub issue

Bug Report

  • I would like to work on a fix!

Current Behavior

Input Code

Expected behavior/code Passing an empty string to parseSync will throw if config file contains exclude.

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

This is sorta documented (https://babeljs.io/docs/en/options#filename) but I find it very confusing 😀 There aren’t really any parse info inferred from filename (I think?), at least not when we pass parserOpts.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
module.exports = {exclude: /react-native/};

Environment

  System:
    OS: macOS Mojave 10.14.6
  Binaries:
    Node: 12.16.3 - ~/.nvm/versions/node/v12.16.3/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v12.16.3/bin/npm
  npmPackages:
    @babel/core: ^7.9.6 => 7.9.6

  • Babel version(s): 7.9.6
  • Node/npm version: v12
  • OS: osx
  • Monorepo: no
  • How you are using Babel: @babel/core’s parseSync

Possible Solution

I would expect this error to be suppressed when we use parse API, same as when we use @babel/parser directly.

Additional context/Screenshots

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
coreyfarrellcommented, May 10, 2020

@nicolo-ribaudo It’s not that the stack frames are missed, it’s just that there are so many they overload the default Error.stackTraceLimit of 10. Here is the complete stack trace @SimenB shared with me, produced when Error.stackTraceLimit = 100; was set:

Error: Configuration contains string/RegExp pattern, but no filename was passed to Babel
    at matchPattern (/Users/simen/repos/jest/node_modules/@babel/core/lib/config/config-chain.js:431:11)
    at /Users/simen/repos/jest/node_modules/@babel/core/lib/config/config-chain.js:418:35
    at Array.some (<anonymous>)
    at matchesPatterns (/Users/simen/repos/jest/node_modules/@babel/core/lib/config/config-chain.js:418:19)
    at configFieldIsApplicable (/Users/simen/repos/jest/node_modules/@babel/core/lib/config/config-chain.js:400:10)
    at configIsApplicable (/Users/simen/repos/jest/node_modules/@babel/core/lib/config/config-chain.js:395:233)
    at /Users/simen/repos/jest/node_modules/@babel/core/lib/config/config-chain.js:245:9
    at Generator.next (<anonymous>)
    at buildRootChain (/Users/simen/repos/jest/node_modules/@babel/core/lib/config/config-chain.js:90:27)
    at buildRootChain.next (<anonymous>)
    at loadPrivatePartialConfig (/Users/simen/repos/jest/node_modules/@babel/core/lib/config/partial.js:95:62)
    at loadPrivatePartialConfig.next (<anonymous>)
    at loadFullConfig (/Users/simen/repos/jest/node_modules/@babel/core/lib/config/full.js:57:46)
    at loadFullConfig.next (<anonymous>)
    at parse (/Users/simen/repos/jest/node_modules/@babel/core/lib/parse.js:27:45)
    at parse.next (<anonymous>)
    at evaluateSync (/Users/simen/repos/jest/node_modules/gensync/index.js:244:28)
    at sync (/Users/simen/repos/jest/node_modules/gensync/index.js:84:14)
    at getAst (/Users/simen/repos/jest/node_modules/istanbul-lib-instrument/dist/read-coverage.js:25:30)
    at readInitialCoverage (/Users/simen/repos/jest/node_modules/istanbul-lib-instrument/dist/read-coverage.js:37:15)
    at Object.<anonymous> (/Users/simen/repos/jest/file.js:5:1)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47

Everything above loadFullConfig from @babel/core/lib/config/full.js is not really helpful to users of babel IMO. One way would be to have a try/catch in loadFullConfig rewrite the stack-trace of config validation errors:

try {
   // call to loadPrivatePartialConfig
} catch (error) {
  if (isConfigValidationError(error) && Error.captureStackTrace) {
    Error.captureStackTrace(error);
  }

  throw error;
}
0reactions
nicolo-ribaudocommented, Aug 27, 2022
  • The underlying issue was fixed a while ago by the fact that now exclude/include can be functions so that can receive an undefined filename.
  • The problem about the unhelpful stack trace was just fixed 😄
Read more comments on GitHub >

github_iconTop Results From Across the Web

Options - Babel.js
Defaults to searching for a default babel.config.json file, but can be passed the path of any JS or JSON5 config file. NOTE: This...
Read more >
codesandbox eslint config | The AI Search Engine You Control
Expected behavior/code Passing an empty string to parseSync will throw if config file contains exclude . Error: Configuration contains string/RegExp pattern, ...
Read more >
Webpack, babel - node_modules are not excluded from bundle
I tried different configuration of .babel-rc, terser and awesome-typescript-loader (exclude /node_modules/) but node_modules are still inside ...
Read more >
babel-loader - webpack
npm install -D babel-loader @babel/core @babel/preset-env webpack ... To exclude node_modules , see the exclude option in the loaders config as documented ...
Read more >
How to Webpack 5 with Babel - Setup Tutorial
By using Babel, the code which isn't supported yet, will get transpiled ... which folders to exclude from the process (e.g. node_modules):.
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