Storybook react: import type Unexpected token, expected "from"
See original GitHub issueCurrent Behavior
import type { CSSVars, Theme } from './utils';
Expected Behavior
Storybook to compile and run fine
Steps to Reproduce
Simple react component inside storybook. Make another library that uses import type and export type.
Import library and it fails
libs\theme\src\index.ts: Unexpected token, expected "from" (6:12)
4 | themeA11yProps,
5 | } from "./utils";
> 6 | import type { CSSVars, Theme } from './utils';
| ^
7 |
8 | export * from './preset';
9 |
at instantiate (C:\dev\clients\Portal.Web\node_modules\@babel\parser\lib\index.js:72:32)
at constructor (C:\dev\clients\Portal.Web\node_modules\@babel\parser\lib\index.js:358:12)
at Parser.raise (C:\dev\clients\Portal.Web\node_modules\@babel\parser\lib\index.js:3341:19)
Issue Analytics
- State:
- Created a year ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Unexpected token then used @storybook/addon-storyshots ...
i used addon-storyshots. But then i run test with jest i have one error. I read many resources how win this problem, but...
Read more >Frequently Asked Questions - Storybook - JS.ORG
In Storybook, you can solve this either by: Adding import React from 'react' to your component files. Adding a .babelrc that includes babel-plugin-react- ......
Read more >Doesn't build (using suggested formatting from Storybook's ...
ts: Unexpected token, expected "from" (1:12) ERR! ERR! > 1 | import type { StorybookConfig } from '@storybook/react/types'; ERR! | ^ ERR! 2...
Read more >Unexpected token import Error in TypeScript | bobbyhadz
To solve the Uncaught SyntaxError: Unexpected token import in TypeScript, set the `module` option to `commonjs` in your `tsconfig.json` file and make sure ......
Read more >Troubleshooting - Material UI - MUI
.storybook/preview.js import { ThemeProvider, createTheme } from ... Ex. 2-2 ✓ Add `React. ... [Jest] SyntaxError: Unexpected token 'export'.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @Coly010
I have the same issue. Looks like the same issue as #9372, but I can’t fix it with a .babelrc file in the library folder.
Here is the smallest reproduction I could make: https://github.com/Lusito/nx-import-type-repro
I first thought, it was a Problem with
import type
, but it generally doesn’t understand typescript in the library.What I found out, is that using
"executor": "@nrwl/web:webpack"
fails, but using"executor": "@nrwl/node:webpack"
works perfectly fine.@Coly010 No repo step anymore. Closing this down looks like its now all working so not sure what the issue is. If i can repo it in a basic setup i’ll reopen. Im so sorry