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

BABEL error when configuring with babel.config.js and with typescript preset #40

Open
jackgeek opened this issue May 14, 2021 · 2 comments

Comments

@jackgeek
Copy link

  • babel-plugin-codegen version: 4.1.4
  • node version: v12.15.0
  • npm version: 6.14.11

With these files:

index.js

// @codegen
module.exports = `console.log("hello world!")`;

babel.config.js

module.exports = {
  presets: ['@babel/preset-typescript'],
  plugins: ['codegen'],
};

I ran this command:

babel --plugins codegen index.js

and got this result:

Error: [BABEL] unknown: Configuration contains string/RegExp pattern, but no filename was passed to Babel
    at matchPattern (/home/jallan/dev/codegen/node_modules/@babel/core/lib/config/config-chain.js:431:11)
    at /home/jallan/dev/codegen/node_modules/@babel/core/lib/config/config-chain.js:418:35
    at Array.some (<anonymous>)
    at matchesPatterns (/home/jallan/dev/codegen/node_modules/@babel/core/lib/config/config-chain.js:418:19)
    at configFieldIsApplicable (/home/jallan/dev/codegen/node_modules/@babel/core/lib/config/config-chain.js:400:10)
    at configIsApplicable (/home/jallan/dev/codegen/node_modules/@babel/core/lib/config/config-chain.js:395:41)
    at /home/jallan/dev/codegen/node_modules/@babel/core/lib/config/config-chain.js:256:13
    at Array.forEach (<anonymous>)
    at /home/jallan/dev/codegen/node_modules/@babel/core/lib/config/config-chain.js:253:42
    at buildPresetChain (/home/jallan/dev/codegen/node_modules/@babel/core/lib/config/config-chain.js:45:17)

Reproduction repository:

https://github.com/jackgeek/codegen-babel-plugin-problem

Problem description:

When using a babel.config.js file the above error occurs, however works fine if you change it to a .babelrc file. Also when you remove the typescript preset it works fine.

@jackgeek
Copy link
Author

jackgeek commented May 14, 2021

Sorry I just realized that I should upgrade babel to the latest in my Proof of Bug repo. I have done this and now I get a different error:

Error: /home/jallan/dev/codegen/index.js: [BABEL] unknown: Preset /* your preset */ requires a filename to be set when babel is called directly,
``
babel.transform(code, { filename: 'file.ts', presets: [/* your preset */] });
``
See https://babeljs.io/docs/en/options#filename for more information.
    at validateIfOptionNeedsFilename (/home/jallan/dev/codegen/node_modules/@babel/core/lib/config/full.js:293:11)
    at /home/jallan/dev/codegen/node_modules/@babel/core/lib/config/full.js:305:52
    at Array.forEach (<anonymous>)
    at validatePreset (/home/jallan/dev/codegen/node_modules/@babel/core/lib/config/full.js:305:25)
    at loadPresetDescriptor (/home/jallan/dev/codegen/node_modules/@babel/core/lib/config/full.js:312:3)
    at loadPresetDescriptor.next (<anonymous>)
    at recursePresetDescriptors (/home/jallan/dev/codegen/node_modules/@babel/core/lib/config/full.js:115:30)
    at recursePresetDescriptors.next (<anonymous>)
    at /home/jallan/dev/codegen/node_modules/@babel/core/lib/config/full.js:189:21
    at Generator.next (<anonymous>) {
  code: 'BABEL_TRANSFORM_ERROR'

I have pushed the changes to the repo

@loynoir
Copy link
Contributor

loynoir commented Aug 31, 2021

@jackgeek Tested fixed by pull/43

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

2 participants