Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

JSX files cannot be imported #21

Open
mattpocock opened this issue Sep 11, 2020 · 4 comments
Open

JSX files cannot be imported #21

mattpocock opened this issue Sep 11, 2020 · 4 comments

Comments

@mattpocock
Copy link
Owner

SyntaxError: C:\...\alert\index.tsx: Unexpected token, expected "," (53:20)

  51 |
  52 |   const list = alerts.map((alert, index) => (
> 53 |     <AlertComponent key={index} status={alert.status}>
     |                     ^
  54 |       ...
@mattpocock
Copy link
Owner Author

Suggested fix would be to add a babel JSX plugin here:

const build = await rollup({
  input: resolvedFilePath,
  external: (id) => !/^(\.|\/|\w:)/.test(id),
  plugins: [
    nodeResolvePlugin({
      extensions,
    }),
    babelPlugin({
      babelHelpers: 'bundled',
      extensions,
      plugins: [
        '@babel/plugin-transform-typescript',
        '@babel/plugin-proposal-optional-chaining',
        ...
      ],
    }),
  ],
});

@rjdestigter
Copy link

I tried with

[
    '@babel/plugin-transform-typescript', { isTSX: true }],
    '@babel/plugin-transform-react-jsx',
]

First without isTSX: true but that didn't make a difference. Setting isTSX to true seems to resolve the issue (I'm running into imported css now lol) but I'm not sure if that's preferable.

@mattpocock
Copy link
Owner Author

@Andarist's new system will be completely Typescript-based, meaning we won't have to worry about Babel configs and can drop a lot of the complexity in extractMachines.ts. The current workaround would probably to put your files with machines in files which don't export JSX files or CSS files. How painful is that for you?

@rjdestigter
Copy link

The current workaround would probably to put your files with machines in files which don't export JSX files or CSS files. How painful is that for you?

Not at all. I was able to refactor the the module being imported from and exclude the files that were using jsx/css.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants