tajo / ladle

🥄 Develop, test and document your React story components faster.
https://www.ladle.dev
MIT License
2.62k stars 93 forks source link

Story discovering failed: [ConfigError: [BABEL] unknown file: Preset /* your preset */ requires a filename to be set when babel is called directly #578

Open viddo opened 1 month ago

viddo commented 1 month ago

I could work around this problem by moving my babel config out of the root dir and reference it by the other tooling that needs it (e.g. Webpack, Jest, …). I don't expect a fix per se, but reporting nevertheless in case someone else runs into this issue. :)


Describe the bug

Adding MDX file with project that have babel config fails upon startup like so:

   ╭───────────────────────────────────────────────────╮
   │                                                   │
   │   🥄 Ladle.dev served at http://localhost:4123/   │
   │                                                   │
   ╰───────────────────────────────────────────────────╯

Story discovering failed:

ConfigError: [BABEL] unknown file: Preset /* your preset */ requires a filename to be set when babel is called directly,

babel.transformSync(code, { filename: 'file.ts', presets: [/* your preset */] });

See https://babeljs.io/docs/en/options#filename for more information.
    at new ConfigError (/home/projects/ladle-o7lxfz/node_modules/.pnpm/@babel+core@7.24.6/node_modules/@babel/core/lib/errors/config-error.js:10:5)
    at validateIfOptionNeedsFilename (/home/projects/ladle-o7lxfz/node_modules/.pnpm/@babel+core@7.24.6/node_modules/@babel/core/lib/config/full.js:265:11)
    at eval (/home/projects/ladle-o7lxfz/node_modules/.pnpm/@babel+core@7.24.6/node_modules/@babel/core/lib/config/full.js:275:103)
    at validatePreset (/home/projects/ladle-o7lxfz/node_modules/.pnpm/@babel+core@7.24.6/node_modules/@babel/core/lib/config/full.js:275:76)
    at loadPresetDescriptor (/home/projects/ladle-o7lxfz/node_modules/.pnpm/@babel+core@7.24.6/node_modules/@babel/core/lib/config/full.js:293:3)
    at recursePresetDescriptors (/home/projects/ladle-o7lxfz/node_modules/.pnpm/@babel+core@7.24.6/node_modules/@babel/core/lib/config/full.js:77:31)
    at eval (/home/projects/ladle-o7lxfz/node_modules/.pnpm/@babel+core@7.24.6/node_modules/@babel/core/lib/config/full.js:156:21)

More info: https://ladle.dev/docs/stories#limitations

Reproduction

  1. Create a new Stackblitz
  2. Add babel.config.json in the root with contents:
    {
    "presets": [
    "@babel/preset-env",
    "@babel/preset-react",
    "@babel/preset-typescript"
    ]
    }
  3. Add/install aforementioned deps
    pnpm add @babel/preset-env @babel/preset-react @babel/preset-typescript
  4. Add a src/whatever.stories.mdx file, contents doesn't matter
  5. Restart dev server pnpm install && pnpm run dev

Environment

tajo commented 2 days ago

fyi: by default, Ladle doesn't use babel anymore (we use swc plugin instead)