react: Bug: react.dev tutorial-tic-tac-toe sample project errors out in modern node versions
Following the step by step instructions for tutorial-tic-tac-toe on react.dev results in errors that make the tutorial impossible to continue.
React version: "react": "^18.0.0", (as specified in package.json)
Node version: 20.5.1
Steps To Reproduce
Follow the instructions for using your local development environment at https://react.dev/learn/tutorial-tic-tac-toe#setup-for-the-tutorial and proceed through the five steps:
- Install Node.js
- In the CodeSandbox tab you opened earlier, press the top-left corner button to open the menu, and then choose File > Export to ZIP in that menu to download an archive of the files locally
- Unzip the archive, then open a terminal and cd to the directory you unzipped
- Install the dependencies with npm install
- Run npm start to start a local server and follow the prompts to view the code running in a browser
When running npm start, see errors in the console, and in the browser:
The process works as intended when using node versions 15 or lower, but fails in the way described above in 16 and above, including the latest, v20
If the intention is that the tutorial files should be run in an outdated version of node, that should be specified up front in the tutorial docs, and enforced in the source code files provided, e.g.
"engines" : {
"node" : "<=15"
}
The current behavior
The application errors out instead of running properly, with no useful error message for the user indicating that this is a problem with the node version.
The expected behavior
The application should not error out, it should run properly, or else should properly notify the user that their node version is incorrect for this codebase.
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Reactions: 5
- Comments: 20 (1 by maintainers)
đ - the new project appears to be misconfigured and breaks when you follow the directions in the tutorial. I would advocate for this to be fixed ASAP; itâs relatively trivial and itâs blocking new engineers from adopting React (not to mention leaving a very bad impression).
@tusharrana786 - if youâre intending to fix this, offering quick fixes is well and good, but the real fix has to be updating the docs or sample project to work as expected đ
Update package.json.
Remove
dev-dependency.react-scriptsAdd
browserlistconfigurationOptionally update
react,react-domandreact-scriptsto latest.Source (old docs): https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html Also, this seems to be part of https://github.com/reactjs/react.dev repository (not sure where the actual zip lives though)
@tusharrana786 - confirmed, updating App.js to
does fix the problem, works fine in latest version of node (v20.5.1)
so it seems like it should be easy enough to address this issue by updating the source code provided in the tutorial?
Iâve tested this and it is working for both the current Codesandbox editor download and the Beta editor. If youâre still seeing issues with this, please file an issue in the docs repo with information about your environment and the specific steps youâre doing and we can re-open to investigate.
The issue here is that the service we use for hosting sandboxes has made a change that makes âdownload to ZIPâ insert an incorrect version of the dependency. It is not a bug in React, it is not a bug in the React website, and it is not due to incorrect instructions or Node versions. It is a mistake in a third-party service, which â thanks to the report â we have now reported to them. Iâm sorry we didnât see it earlier. As you might have guessed, at the time this tutorial was written, this bug in the âdownload to ZIPâ feature of CodeSandbox did not exist yet.
I can open a different ticket for it, but this is not the only node version related problem with the tutorial code - very nearly the next step instructs you to add a fragment like so:
which results in an error in node v20 -
but works fine in node v15.
Iâll go ahead and keep walking through the tutorial steps, but this does seem like itâs going to require a bit of work to dig out version incompatibilities. This is the first tutorial that users are directed to after landing on the site, so itâs a bit worrisome how easy it is to run into these roadblocks, without much in the way of warning as to whatâs causing the issues.
I am brand new to react and js and it is funny that all I hear about is how react projects are a dependency nightmare and that projects break all the time. The first tutorial I try and it is broken due to changes in how to approach react development.
I concur that adding the import statement is a quick fix - but it is the same problem that I see over and over: a quick fix.
It is my understanding that the latest versions of react do not require the import statement. In an attempt to follow what I could online, I followed https://kinsta.com/knowledgebase/react-must-be-in-scope-when-using-jsx/ which suggested the following additions to the package.json file:
This however did not work. After deleting node_modules and trying again, which failed the same way, so I attempted to
npm install react-scripts@latestwhich then caused the following:And running that did not work:
Then subsequent commands would error out with:
I was only able to remedy the situation by nuking the changes I had made and then following the suggestion here of adding the
import React from "react";line toApp.js.I can see why the quick fix is tempting, after all, you simply just add the one line and the project works again. However, there is something deeper that is broken in this tutorial as it requires a hack to allow âmodernâ react development.
This appears to be a bug in CodeSandbox, which weâll report to them.
For future reference, please report React website bugs to the React website repository: https://github.com/reactjs/react.dev/
This repository is for React bugs, and so unfortunately unrelated things can get missed here.
FWIW that hasnât been my experience so far @dietervdwes; most of the docs are quite good and this is an outlier. Donât be deterred đ
not sure if it is the same bug or a different one since it is about versions. Following the tutorial, I am unable to use the more modern fragment syntax:
My workaround is to not use
<></>but to use<div></div>