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

Configuration contains string/RegExp pattern, but no filename was passed to Babel #11035

Closed
budarin opened this issue Jan 21, 2020 · 3 comments
Closed
Assignees
Labels
area: third party i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@budarin
Copy link

budarin commented Jan 21, 2020

Bug Report

Current Behavior
The project uses typescript as a type checker not as transpiler.
I have working babel config (project runs correctly), but when I try to run jest test - it fails with the error:

Error Code

 FAIL  src/__tests__/server.test.ts
   Test suite failed to run

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

      at matchPattern (node_modules/@babel/core/lib/config/config-chain.js:431:11)
      at node_modules/@babel/core/lib/config/config-chain.js:418:35
          at Array.some (<anonymous>)
      at matchesPatterns (node_modules/@babel/core/lib/config/config-chain.js:418:19)
      at shouldIgnore (node_modules/@babel/core/lib/config/config-chain.js:404:17)
      at node_modules/@babel/core/lib/config/config-chain.js:272:11
          at Array.some (<anonymous>)
      at node_modules/@babel/core/lib/config/config-chain.js:267:26
      at buildRootChain (node_modules/@babel/core/lib/config/config-chain.js:90:27)

Expected behavior/code
Expected tests to be run

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

  • Filename: babel.config.json
{
    "comments": false,
    "presets": [
        [
            "@babel/preset-env",
            {
                "loose": true,
                "debug": false,
                "modules": false,
                "corejs": {
                    "version": 3,
                    "proposals": true
                },
                "useBuiltIns": "usage",
                "targets": { "node": "current" }
            }
        ],
        "@babel/typescript"
    ],
    "plugins": ["preval"],
    "env": {
        "production": {
            "ignore": ["**/*.test.tsx", "**/*.test.ts", "__snapshots__", "__tests__"]
        },
        "development": {
            "ignore": ["**/*.test.tsx", "**/*.test.ts", "__snapshots__", "__tests__"]
        },
        "test": {
            "ignore": ["__snapshots__"]
        }
    }
}
  • Filename: jest.config.js
module.exports = {
    globals: {
        'ts-jest': {
            babelConfig: true,
        },
    },
    moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],
    preset: 'ts-jest',
    testEnvironment: 'node',
    testMatch: ['**/__tests__/**/*.(spec|test).[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'],
}
  • Filename: tscconfig.json
{
    "compilerOptions": {
        "resolveJsonModule": true,
        "incremental": true,
        "target": "esnext",
        "module": "commonjs",
        "allowJs": true,
        "outDir": "./dist",
        "noEmit": true ,
        "forceConsistentCasingInFileNames": true,
        "strict": true,
        "noImplicitAny": true,
        "strictNullChecks": true,
        "strictFunctionTypes": true,
        "strictBindCallApply": true,
        "strictPropertyInitialization": true,
        "noImplicitThis": true,
        "alwaysStrict": true,
        "baseUrl": ".",
        "esModuleInterop": true ,
    },
    "include": ["types", "src"],
    "exclude": ["node_modules", "dist", "jest-coverage", "config"]
}

Environment

System:
    OS: macOS 10.15.2
  Binaries:
    Node: 13.5.0 - /usr/local/bin/node
    Yarn: 1.9.4 - /usr/local/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
  npmPackages:
    @babel/cli: ^7.8.3 => 7.8.3 
    @babel/core: ^7.8.3 => 7.8.3 
    @babel/preset-env: ^7.8.3 => 7.8.3 
    @babel/preset-typescript: ^7.8.3 => 7.8.3 
    babel-jest: ^24.9.0 => 24.9.0 
    babel-loader: ^8.0.6 => 8.0.6 
    babel-plugin-preval: ^4.0.0 => 4.0.0 
    eslint: ^6.8.0 => 6.8.0 
    jest: ^24.9.0 => 24.9.0 
    webpack: ^4.41.5 => 4.41.5 

Additional context/Screenshots
I started to suspect that the problem was in the env block in babel.config.js - so I have removed it, but got another strange error:

 Test suite failed to run

   /src/utils/initApp.ts:3
    import "core-js/modules/esnext.set.add-all";
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

       5 | import api from './middlewares/api';
       6 | import echo from './middlewares/echo';
    >  7 | import initApp from './utils/initApp';
         | ^
       8 | import healthCheck from './middlewares/healthCheck';
       9 | import responseTime from './middlewares/responseTime';
      10 | import aboutService from './middlewares/aboutService';

      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
      at Object.<anonymous> (src/index.ts:7:1)

adding to jest.config

    transform: {
        '^.+\\.(js|jsx|ts|tsx|json)$': 'babel-jest',
    },

also produces the above error

@babel-bot
Copy link
Collaborator

Hey @budarin! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@JLHwung JLHwung self-assigned this Feb 12, 2020
@JLHwung
Copy link
Contributor

JLHwung commented Feb 12, 2020

I can reproduce on my local repo.

Maybe related: #9475

@JLHwung
Copy link
Contributor

JLHwung commented Feb 12, 2020

Please update ts-jest to v25.2.0, which includes kulshekhar/ts-jest#1370 that happens to fix this issue.

@JLHwung JLHwung closed this as completed Feb 12, 2020
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 13, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: third party i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants