question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Storybook react: import type Unexpected token, expected "from"

See original GitHub issue

Current 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:closed
  • Created a year ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
Lusitocommented, Jun 17, 2022

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.

1reaction
Jordan-Hallcommented, Jun 20, 2022

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found