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

v2_dev build not parsing JSX in javascript #7051

Closed
1 task done
brentmjohnson opened this issue Aug 3, 2023 · 10 comments · Fixed by #7112
Closed
1 task done

v2_dev build not parsing JSX in javascript #7051

brentmjohnson opened this issue Aug 3, 2023 · 10 comments · Fixed by #7112

Comments

@brentmjohnson
Copy link

brentmjohnson commented Aug 3, 2023

What version of Remix are you using?

1.19.1

Are all your remix dependencies & dev-dependencies using the same version?

  • Yes

Steps to Reproduce

see https://github.com/brentmjohnson/remixQuickStart for reproducible example.

  • init new project from template npx create-remix@latest --template https://github.com/remix-run/remix/tree/main/templates/express ./ --no-typescript

    notice tsx files are still created instead of js

  • replace the following files with valid js versions:

    app/routes/_index.tsx
    app/entry.client.tsx
    app/entry.server.tsx
    app/root.tsx
    
  • npm run build succeeds:

    $ npm run build
    
    > build
    > remix build
    
     info  building... (NODE_ENV=production)
     info  built (240ms)
    
  • npm run dev fails:

    $ npm run dev
    
    > dev
    > remix dev --manual -c "node server.js"
    
    
     💿  remix dev
    
     info  building...
    ✘ [ERROR] Expected ">" but found "/"
    
        app/entry.client.js:23:20:
          23 │       <RemixBrowser />
             │                     ^
             ╵                     >
    
    
    ✘ [ERROR] Expected ">" but found "lang"
    
        app/root.js:55:15:
          55 │   return <html lang="en">
             │                ~~~~
             ╵                >
    
    
    ✘ [ERROR] Expected ">" but found "style"
    
        app/routes/_index.js:30:14:
          30 │   return <div style={{
             │               ~~~~~
             ╵               >
    

Expected Behavior

remix dev build occurring in v2_dev should succeed like remix production build

Actual Behavior

remix dev build occurring in v2_dev fails

@brophdawg11
Copy link
Contributor

I'm not sure what happened in your case, but npx create-remix@latest --template https://github.com/remix-run/remix/tree/main/templates/express ./ --no-typescript does not generate TS files when I run it.

The error you're seeing is because you renamed the files to .js instead of .jsx. It should work if you change those to .jsx.

@brophdawg11 brophdawg11 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 4, 2023
@brophdawg11 brophdawg11 assigned brophdawg11 and unassigned pcattori Aug 4, 2023
@brophdawg11 brophdawg11 moved this from Backlog to Closed in v2 Aug 4, 2023
@brentmjohnson
Copy link
Author

Fair to mark this as not planned, but it is a breaking change from v2_dev: false and differs from remix build which was confusing to me at least.

Note that esbuild does support jsx in js: https://esbuild.github.io/content-types/#jsx

In my case, I have a pre remix build step for babel to transpile the ts/tsx to support relay macros. Previously babel was leaving the jsx unmodified in the js output as it seems preferable to have remix build do all react specific transforms. The workaround for now was to go ahead and have babel transform that jsx rather than remix.

Let me know if jsx in js support is reconsidered for v2_dev.

@pcattori pcattori reopened this Aug 7, 2023
@pcattori pcattori assigned pcattori and unassigned brophdawg11 Aug 7, 2023
@MichaelDeBoey MichaelDeBoey moved this from Closed to Backlog in v2 Aug 7, 2023
@jaschaio
Copy link

jaschaio commented Aug 9, 2023

I run into the same issue. It's definitely a breaking change not mentioned in the documentation. @brentmjohnson did you find any suitable workaround beside renaming hundreds of files from .js to .jsx?

@jaschaio
Copy link

jaschaio commented Aug 9, 2023

I also wonder why it differs between remix build and remix dev where the former works and the latter fails with the above errors.

@jaschaio
Copy link

jaschaio commented Aug 9, 2023

Looks like the reason it differs between remix build and remix dev is due to the hmr plugin.

I suspect the @babel/plugin-syntax-jsx is the one actually causing trouble https://github.com/remix-run/remix/blob/main/packages/remix-dev/compiler/js/plugins/hmr.ts#L166

@jaschaio
Copy link

jaschaio commented Aug 9, 2023

Or might be caused by @babel/preset-typescript. I tried the isTXS and allExtensions options but continue to get the same rror.

@jaschaio
Copy link

jaschaio commented Aug 9, 2023

Ok, even simpler. This change in line https://github.com/remix-run/remix/blob/main/packages/remix-dev/compiler/js/plugins/hmr.ts#L142 works for me:

--- a/node_modules/@remix-run/dev/dist/compiler/js/plugins/hmr.js
+++ b/node_modules/@remix-run/dev/dist/compiler/js/plugins/hmr.js
@@ -161,7 +161,7 @@ declare global {
             sourceCode,
             output: {
               contents: resultCode,
-              loader: args.path.endsWith("x") ? "tsx" : "ts",
+              loader: "tsx",
               resolveDir: path__namespace.dirname(args.path)
             }
           };

@pcattori pcattori linked a pull request Aug 9, 2023 that will close this issue
@pcattori pcattori moved this from Backlog to PR in v2 Aug 9, 2023
@pcattori
Copy link
Contributor

pcattori commented Aug 9, 2023

Fixed by #7112

@pcattori pcattori closed this as completed Aug 9, 2023
@pcattori pcattori moved this from PR to Closed in v2 Aug 9, 2023
@brentmjohnson
Copy link
Author

I run into the same issue. It's definitely a breaking change not mentioned in the documentation. @brentmjohnson did you find any suitable workaround beside renaming hundreds of files from .js to .jsx?

@jaschaio, just for reference and for those using babel for pre-transpile before remix build there were 2 ways to address something like this as a workaround in case something similar comes up:

  1. add --keep-file-extension to your babel cli call where the output directory is your remix build directory (./app). this allows remix to continue to perform the react / jsx transform.
  2. add the following to your babel.config.json plugins. this instructs babel to perform the react / jsx transform:
[
  "@babel/plugin-transform-react-jsx",
  {
    "runtime": "automatic"
  }
]

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v0.0.0-nightly-b1149bb-20230810 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Merged
Development

Successfully merging a pull request may close this issue.

4 participants