jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.22k stars 507 forks source link

@babel/core v7.13.0 bugs causing builds to fail on new installs #977

Closed marklawlor closed 3 years ago

marklawlor commented 3 years ago

Current Behavior

npx tsdx create my-project

Choose react with storybook

Errors during the build phase with

(babel plugin) TypeError: Cannot read property 'resolved' of undefined
TypeError: Cannot read property 'resolved' of undefined
    at /home/user/my-project/node_modules/tsdx/dist/babelPluginTsdx.js:19:94
    at Array.findIndex (<anonymous>)
    at /home/user/my-project/node_modules/tsdx/dist/babelPluginTsdx.js:19:54
    at Array.forEach (<anonymous>)
    at /home/user/my-project/node_modules/tsdx/dist/babelPluginTsdx.js:18:27
    at Array.forEach (<anonymous>)
    at Object.exports.mergeConfigItems (/home/user/my-project/node_modules/tsdx/dist/babelPluginTsdx.js:17:24)
    at Object.config (/home/user/my-project/node_modules/tsdx/dist/babelPluginTsdx.js:109:40)
    at transformCode (/home/user/my-project/node_modules/@rollup/plugin-babel/dist/index.js:239:86)
    at async Promise.all (index 0)

It appears the latest version of @babel/core broke the config merging.

Expected behavior

TSDX can create new projects

Suggested solution(s)

Current workaround is to lock package.json to "@babel/core": "7.12.17" via resolutions

"resolutions": {
  "**/@babel/core": "7.12.17"
}

Additional context

Your environment

System:
    OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 5.76 GB / 15.37 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 12.19.0 - ~/.nvm/versions/node/v12.19.0/bin/node
    Yarn: 1.22.5 - /usr/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v12.19.0/bin/npm
  Browsers:
    Chrome: 88.0.4324.182
    Firefox: 85.0.1
marklawlor commented 3 years ago

This seems to fix the build, but the Storybook is failing with

Uncaught TypeError: _interopRequireDefault is not a function
    at Object../node_modules/react-syntax-highlighter/dist/cjs/languages/prism/jsx.js (vendors~main.96bbda1226654fa44563.bundle.js:141158)
    at __webpack_require__ (runtime~main.96bbda1226654fa44563.bundle.js:849)
    at fn (runtime~main.96bbda1226654fa44563.bundle.js:151)
    at Object../node_modules/@storybook/components/dist/syntaxhighlighter/syntaxhighlighter.js (vendors~main.96bbda1226654fa44563.bundle.js:29490)
    at __webpack_require__ (runtime~main.96bbda1226654fa44563.bundle.js:849)
    at fn (runtime~main.96bbda1226654fa44563.bundle.js:151)
    at Object../node_modules/@storybook/components/dist/index.js (vendors~main.96bbda1226654fa44563.bundle.js:29046)
    at __webpack_require__ (runtime~main.96bbda1226654fa44563.bundle.js:849)
    at fn (runtime~main.96bbda1226654fa44563.bundle.js:151)
    at Object../node_modules/@storybook/addon-essentials/node_modules/@storybook/addon-docs/dist/blocks/index.js (vendors~main.96bbda1226654fa44563.bundle.js:10641)
marklawlor commented 3 years ago

Related babel issues

Config merging (looks like tsdx uses the logic as Gatsby): https://github.com/babel/babel/issues/12851 _interopRequireDefault is not a function: https://github.com/babel/babel/issues/12854

hzoo commented 3 years ago

@marklawlor yep looks like the same issue with createConfigItem, so should be fixed soon https://github.com/formium/tsdx/blob/462af2d002987f985695b98400e0344b8f2754b7/src/babelPluginTsdx.ts#L1

agilgur5 commented 3 years ago

It appears the latest version of @babel/core broke the config merging.

Yes, @babel/core v7.13.0 was released just two hours ago and seems to have several bugs. https://github.com/babel/babel/issues/12851 is this error and https://github.com/babel/babel/issues/12852 recently fixed it an hour ago.

It is an upstream bug in Babel that many packages are hitting; it's not something TSDX can control. It's also incredibly recent and likely to be fixed by tomorrow if not within the next few hours.

Current workaround is to lock package.json to "@babel/core": "7.12.17" via resolutions

You can also set your yarn.lock or package-lock.json. TSDX does not pin a newer version.

but the Storybook is failing with

That is also a bug in Babel, https://github.com/babel/babel/issues/12854, filed an hour ago, that was closed 5 minutes ago in https://github.com/babel/babel/issues/12855.

TSDX does not even depend on Storybook, it's just included in one of the templates, so a bug in Storybook is also not something TSDX can control. But neither can Storybook as that's a bug in Babel.

Would recommend focusing time upstream, but thanks for providing a workaround @marklawlor that should suffice for anyone installing within the next day or so until this is fixed upstream. (Yes, TSDX could hard pin to resolve this, but as I've previously stated, having all downstream packages churn multiple releases is not a good solution to an upstream issue -- contributing upstream is)

hzoo commented 3 years ago

It's also incredibly recent and likely to be fixed by tomorrow if not within the next few hours.

@agilgur5, yep publishing a new version now! https://github.com/babel/babel/runs/1957418439

hzoo commented 3 years ago

Ah it published when I posted, it should be fixed if you try again https://github.com/babel/babel/releases/tag/v7.13.1

agilgur5 commented 3 years ago

Thanks @hzoo, y'all rock!

agilgur5 commented 3 years ago

@marklawlor if you could confirm the fix and close out, that'd be great. I think the added tests in the Babel PRs cover our use-cases, but might find something else -- please report upstream to help the Babel team if so.

derrickmehaffy commented 3 years ago

Hi from another node project Strapi o/

We tested v7.13.1 and it did not fix it for us, we issued a workaround for our community here: https://github.com/strapi/strapi/issues/9482#issuecomment-783797102

marklawlor commented 3 years ago

@agilgur5 v7.13.1 works for a clean install.

@derrickmehaffy cheers that fixed the last issue with my project