storybook: [Storybook 6] The "zero-config" TypeScript config doesn't work on our project
Describe the bug
A clear and concise description of what the bug is.
Build error for 2 syntaxes:
- const enum
declareclass fields
ERROR in ./src/plugins/FileService/constants.ts
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /home/jack/workspace/maskbook/src/plugins/FileService/constants.ts: 'const' enums are not supported.
9 | export const signing = 'https://service.maskbook.com/arweave-remote-signing'
10 |
> 11 | export const enum FileRouter {
| ^
12 | upload = '/upload',
13 | uploading = '/uploading',
14 | uploaded = '/uploaded',
ERROR in ./src/utils/ObservableMapSet.ts
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /home/jack/workspace/maskbook/src/utils/ObservableMapSet.ts: TypeScript 'declare' fields must first be transformed by @babel/plugin-transform-typescript.
If you have already enabled that plugin (or '@babel/preset-typescript'), make sure that it runs before any plugin related to additional class features:
- @babel/plugin-proposal-class-properties
- @babel/plugin-proposal-private-methods
- @babel/plugin-proposal-decorators
2 | // Consider switch to libraries like Mobx if this file become too complex.
3 | export class ObservableWeakMap<K extends object, V> extends WeakMap<K, V> {
> 4 | declare __brand: 'Map'
| ^^^^^^^^^^^^^^^^^^^^^^
5 |
6 | event = new Emitter<{ delete: [K]; set: [K, V] }>()
7 | delete(key: K) {
To Reproduce
Reproduction: https://github.com/DimensionDev/Maskbook/pull/1568
Expected behavior Build successfully
System:
Please paste the results of npx sb@next info here.
Environment Info:
System:
OS: Linux 5.8 Arch Linux
Binaries:
Node: 14.10.0 - /usr/bin/node
Yarn: 1.22.5 - /usr/bin/yarn
npm: 6.14.7 - /usr/bin/npm
npmPackages:
@storybook/addon-actions: ^6.0.21 => 6.0.21
@storybook/addon-docs: ^6.0.21 => 6.0.21
@storybook/addon-info: ^5.3.21 => 5.3.21
@storybook/addon-knobs: ^6.0.21 => 6.0.21
@storybook/addon-links: ^6.0.21 => 6.0.21
@storybook/addon-viewport: ^6.0.21 => 6.0.21
@storybook/addons: ^6.0.21 => 6.0.21
@storybook/react: ^6.0.21 => 6.0.21
Additional context
Add any other context about the problem here.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 56
- Comments: 26 (3 by maintainers)
If you want this fixed, please upvote by adding a 👍 to the issue description. We use this to help prioritize!
For anyone running into an issue with
declareclass fields, here is what worked for me:I wish I’d be able to preserve more of Storybook’s configuration as-is but turning on
allowDeclareFieldsisn’t enough. This transform also has to be applied before the other conflicting plugins.I’m surprised this is labeled a “question / support” issue and not bug, considering the two issues reported here literally mean there isn’t “zero configuration needed” for TypeScript projects. I can appreciate there might be more urgent things to fix but surely it wouldn’t take that much effort to amend this documentation with reference to unsupported TypeScript syntax until the issue is fixed.
Similar to other solutions, but this one worked for my project
in
main.jsBabel config is the part that is modified
Had the same issue and was able to fix it by adding
babel-plugin-const-enumand a .babelrc file in my .storybook folder as below.Hi everyone! Seems like there hasn’t been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don’t have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!
It seems that you can make it work by using those babel presets: babel-preset-const-enum and babel-preset-typescript.
Then in your .babelrc file, you can add:
It allows you to have a mix of stories written in .mdx and .tsx.
If you have an error mentionning
isLeaf, it certainly mean that you have stories with same titles and it should be fixed by having different titles.Had the same issue with const-enum, patched webpack config such as
Just installing babel-plugin-const-enum not helped.