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

JavaScript generated react apps create and index.html that references main.tsx instead of main.jsx, and create .js files not .jsx files which generates errors in build target #20810

Closed
1 of 4 tasks
Phiponacci opened this issue Dec 17, 2023 · 1 comment · Fixed by #27130
Assignees
Labels
outdated scope: react Issues related to React support for Nx type: bug

Comments

@Phiponacci
Copy link

Phiponacci commented Dec 17, 2023

Current Behavior

[vite]: Rollup failed to resolve import "/src/main.tsx" from "path/to/workspace/ui/apps/admin/index.html".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
build.rollupOptions.external

NX [vite]: Rollup failed to resolve import "/src/main.tsx" from "path/to/workspace/ui/apps/admin/index.html".

Expected Behavior

  • Executing task: yarn nx run admin:build --configuration=development

yarn run v1.22.19
$ path/to/workspace/ui/node_modules/.bin/nx run admin:build --configuration=development

nx run admin:build:development [local cache]

vite v5.0.10 building for development...
✓ 33 modules transformed.
../../dist/apps/admin/index.html 0.48 kB │ gzip: 0.30 kB
../../dist/apps/admin/assets/index-f0mNRiTD.css 0.00 kB │ gzip: 0.02 kB
../../dist/apps/admin/assets/index-NYD0XF7l.js 167.40 kB │ gzip: 51.96 kB
✓ built in 1.38s

———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

NX Successfully ran target build for project admin (83ms)

Nx read the output from the cache instead of running the command for 1 out of 1 tasks.

View logs and run details at https://nx.app/runs/OuB24bgKAY

Done in 0.44s.

  • Terminal will be reused by tasks, press any key to close it.

GitHub Repo

No response

Steps to Reproduce

  1. create a workspace using the following command: npx create-nx-workspace --pm yarn --js
  2. generate a react application with js enabled in the nx console extension in VS Code

Screenshot from 2023-12-17 08-34-46

  1. build the generated app

Nx Report

>  NX   Report complete - copy this into the issue template

   Node   : 20.10.0
   OS     : linux-x64
   yarn   : 1.22.19
   
   nx (global)        : v17.2.5
   nx                 : v17.2.5
   @nx/js             : v17.2.5
   @nx/linter         : v17.2.5
   @nx/eslint         : v17.2.5
   @nx/workspace      : v17.2.5
   @nx/devkit         : v17.2.5
   @nx/eslint-plugin  : v17.2.5
   @nx/react          : v17.2.5
   @nrwl/tao          : v17.2.5
   @nx/vite           : v17.2.5
   @nx/web            : v17.2.5
   typescript         : 5.2.2

Failure Logs

> nx run admin:build:development

vite v5.0.10 building for development...
✓ 2 modules transformed.
[vite]: Rollup failed to resolve import "/src/main.tsx" from "path/to/workspace/ui/apps/admin/index.html".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`

 >  NX   [vite]: Rollup failed to resolve import "/src/main.tsx" from "path/to/workspace/ui/apps/admin/index.html".

   This is most likely unintended because it can break your application at runtime.
   If you do want to externalize this module explicitly add it to
   `build.rollupOptions.external`
   Pass --verbose to see the stacktrace.


 ———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 >  NX   Ran target build for project admin (1s)
 
    ✖    1/1 failed
    ✔    0/1 succeeded [0 read from cache]
 
   View structured, searchable error logs at https://nx.app/runs/TjxJ8enSEB

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

 *  The terminal process "/usr/bin/bash '-c', 'yarn nx run admin:build --configuration=development'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it.

Package Manager Version

yarn 1.22.19

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

I renamed the .js files to .jsx, and changed main.tsx to main.jsx in the index.html file, that makes it work, i think the problem is in the generator, so I don't want each time to do the same process, any help will be appreciated. Thank you in advance.

@mandarini mandarini added the scope: react Issues related to React support for Nx label Dec 18, 2023
@jaysoo jaysoo assigned jaysoo and unassigned ndcunningham Jul 25, 2024
@jaysoo jaysoo closed this as completed in 45c458e Jul 26, 2024
FrozenPandaz pushed a commit that referenced this issue Jul 30, 2024
The current `@nx/react:app` generator does not take the `--js` option
into account. There are two problems:

1. `index.html` includes `main.tsx` not `main.jsx`.
2. `.js` files with JSX are invalid in Vite, and must be named `.jsx`.

This PR adds a new option to the `toJS` devkit util to preserve `.jsx`
rather than renaming them to `.js`. The vast majority of non-Vite React
projects will use `.js` and not `.jsx` (e.g. Next.js, Expo, Remix, etc.)
so we just want to apply this change to Vite only for now.

In the future we could enhance React generators to support `--jsx`, for
example.

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #20810

(cherry picked from commit 45c458e)
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: react Issues related to React support for Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants