Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsx parse error #53

Closed
rambabusaravanan opened this issue Jul 15, 2021 · 4 comments
Closed

jsx parse error #53

rambabusaravanan opened this issue Jul 15, 2021 · 4 comments

Comments

@rambabusaravanan
Copy link

Hi @fwouts,

When using our components, I'm facing issue in parsing jsx file.

% yarn test:visual:new shoot
yarn run v1.22.5
$ viteshot shoot
10:58:20 [vite] new dependencies found: styled-components, mylib, gatsby, react-hook-form, query-string, recoil, updating...
10:58:20 [vite] error while updating dependencies:
Error: Parse error @:28:55
    at parse$e (/Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/vite/dist/node/chunks/dep-11db14da.js:28902:353)
    at optimizeDeps (/Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/vite/dist/node/chunks/dep-11db14da.js:73082:29)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async rerun (/Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/vite/dist/node/chunks/dep-11db14da.js:73388:61)
10:58:21 [vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
  Plugin: vite:import-analysis
  File: /Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/gatsby/cache-dir/gatsby-browser-entry.js
  26 |      <React.Fragment>
  27 |        {finalData && render(finalData)}
  28 |        {!finalData && <div>Loading (StaticQuery)</div>}
     |                                                        ^
  29 |      </React.Fragment>
  30 |    )
      at formatError (/Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/vite/dist/node/chunks/dep-11db14da.js:50684:46)
      at TransformContext.error (/Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/vite/dist/node/chunks/dep-11db14da.js:50680:19)
      at TransformContext.transform (/Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/vite/dist/node/chunks/dep-11db14da.js:74063:22)
      at async Object.transform (/Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/vite/dist/node/chunks/dep-11db14da.js:50885:30)
      at async transformRequest (/Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/vite/dist/node/chunks/dep-11db14da.js:66636:29)
      at async viteTransformMiddleware (/Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/vite/dist/node/chunks/dep-11db14da.js:66774:32)
10:58:21 [vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
  Plugin: vite:import-analysis
  File: /Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/gatsby/cache-dir/gatsby-browser-entry.js
  26 |      <React.Fragment>
  27 |        {finalData && render(finalData)}
  28 |        {!finalData && <div>Loading (StaticQuery)</div>}
     |                                                        ^
  29 |      </React.Fragment>
  30 |    )
      at formatError (/Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/vite/dist/node/chunks/dep-11db14da.js:50684:46)
      at TransformContext.error (/Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/vite/dist/node/chunks/dep-11db14da.js:50680:19)
      at TransformContext.transform (/Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/vite/dist/node/chunks/dep-11db14da.js:74063:22)
      at async Object.transform (/Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/vite/dist/node/chunks/dep-11db14da.js:50885:30)
      at async transformRequest (/Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/vite/dist/node/chunks/dep-11db14da.js:66636:29)
      at async viteTransformMiddleware (/Users/rambabusaravanan/workspace/xxx/xxxxxx/node_modules/vite/dist/node/chunks/dep-11db14da.js:66774:32) (x2)

Earlier I used to declare in jest.screenshot.config.js file

transformIgnorePatterns: [`node_modules/(?!(gatsby|mylib)/)`]
@fwouts
Copy link
Owner

fwouts commented Jul 15, 2021

Hey @rambabusaravanan, great bug report.

Viteshot currently can't support any JSX in js files, but I just managed to get that to work in reactpreview.com, which works in a very similar way, so I should be able to fix it.

Give me a day or two 🙂

@fwouts
Copy link
Owner

fwouts commented Jul 15, 2021

Hey @rambabusaravanan, v0.1.4 is out with support for JSX in .js files.

However, this cannot apply to JSX inside node_modules/, which appears to be the case with Gatsby. In case you're curious, the problematic code inside Vite is https://github.com/vitejs/vite/blob/887c247984abc0f80d8b19a1d681855944f6d01a/packages/vite/src/node/optimizer/index.ts#L245

It looks like you won't be able to take screenshots of components that depend on Gatsby 😞 Other, more isolated components should however be fine.

@fwouts
Copy link
Owner

fwouts commented Aug 27, 2021

Hey @rambabusaravanan, it took a while to get that PR merged into Vite, but it's now done :)

You should be able to use Viteshot with Gatsby, at least from v0.1.8. Let me know how you go!

@fwouts fwouts closed this as completed Aug 27, 2021
@rambabusaravanan
Copy link
Author

Sure will give it a try. Thanks for the update.

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

No branches or pull requests

2 participants