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

It should be possible to start the front end and back end with a single command #25

Closed
OldManLink opened this issue Mar 26, 2020 · 18 comments
Assignees

Comments

@OldManLink
Copy link

This is a description of how the project works for me under Mac OS X Catalina, along with a suggestion of how I think it should work.

  • From the root directory, I start the back end with the command sbt run

  • After everything is built and the server has started, the following output appears in the console:

> scala-play-react-seed@1.0.0 start /Users/peter/CodeRoot/other/scala-play-react-seed/ui
> react-scripts start

ℹ 「wds」: Project is running at http://10.0.0.69/
ℹ 「wds」: webpack output is served from 
ℹ 「wds」: Content not from webpack is served from /Users/peter/CodeRoot/other/scala-play-react-seed/ui/public
ℹ 「wds」: 404s will fallback to /
Starting the development server...
  • The browser now opens at the url http://localhost:3000/. This page is blank, and the error message in Chrome is as follows:
This site can’t be reached
localhost refused to connect.
  • I open a new console and execute the following:
cd ui
npm start

The output in the new console is as follows:

Compiled successfully!

You can now view hivetest in the browser.

  Local:            http://localhost:3000
  On Your Network:  http://10.0.0.69:3000

Note that the development build is not optimized.
To create a production build, use yarn build.
  • The browser automatically reloads http://localhost:3000/ and displays the React application as expected.

I would have expected the last stage to happen automatically, making the manual step unnecessary.

@yohangz yohangz self-assigned this Mar 26, 2020
@yohangz
Copy link
Contributor

yohangz commented Mar 26, 2020

Yes, sbt run should load the frontend application properly.

It clearly runs the same command via the run hook and your issue summary confirms it. Could you please share the full log dump to investigate further. It works perfectly fine in my environment.

I hope you had the port 3000 free at the time of the initial run.

@OldManLink
Copy link
Author

Thanks! I can confirm that port 3000 was free before the initial run.

I have copied the console output to a new file called logs/console.log, and logs/application.log is untouched by me. Here is the zip file of the logs directory:
logs.zip

@OldManLink
Copy link
Author

Note: The above was based on a fresh install from the downloaded zip file, and it also worked fine once I invoked cd ui ; npm start in a secondary console. I have annotated the point when this occurred.

@yohangz
Copy link
Contributor

yohangz commented Mar 26, 2020

I did some debugging and found that there is an issue when invoking react-scripts through a process initiated from a different directory outside of React project root. This used to work well with older react versions but the latest react updates broke the functionality. I might have to debug further.

@OldManLink
Copy link
Author

I see that the issue about this has been closed, so it doesn't look as if there are plans to fix it. Shall I take a look in FrontendRunHook and see if the suggested cwd can be done in there?

@OldManLink
Copy link
Author

I have not had any luck with that, but I can confirm that this change makes everything work again:

18:24 $ git diff
diff --git a/ui/package.json b/ui/package.json
index 94301df..b981ff6 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -14,7 +14,7 @@
     "react": "^16.8.6",
     "react-dom": "^16.8.6",
     "react-router-dom": "^5.0.1",
-    "react-scripts": "^3.0.1"
+    "react-scripts": "2.1.8"
   },
   "devDependencies": {
     "ncp": "^2.0.0",
✔ ~/CodeRoot/other/scala-play-react-seed [master|✚ 1]

So this confirms that the problem is caused by react-scripts version 3.0.1

For my part, this change is sufficient for now, and I am no longer stuck. If you wish to close the issue that is fine by me, but should you find a better solution I'd still like to know.

@yohangz
Copy link
Contributor

yohangz commented Mar 28, 2020

Thanks for the confirmation. My goal is to support the latest version of React. I will debug further and see whether there is a workaround.

@Suedo
Copy link

Suedo commented Apr 1, 2020

I am facing a similar situation. This project has javascript react, and since I would prefer Typescript, i rm -rfd the ui folder, and created a new one using create-react-app with the typescript flag.

Everything else is the same, and I have modified the package.json with ncp and rimraf, as mentioned in your medium article.

But, when I do sbt run in the root localtion, the browser opens up at localhost:3000 but then gives the error that OP mentioned.

To bring the UI up in localhost:3000, I need to manually go into the ui folder in terminal, and do yarn start.

If you could help in understanding why this is happening, would be great!

Link to my 'fork' : https://github.com/Suedo/PlayScalaReact

I am also on OSX catalina

@AlexTo
Copy link

AlexTo commented Apr 2, 2020

subscribed ;)

guillegr123 added a commit to guillegr123/pictionary-web that referenced this issue Apr 10, 2020
@pedrorijo91
Copy link

+1 here. I don't have a lot of experience in react, but let me/us know if there's some way we can help with this issue :)

@nelsonblaha
Copy link

+1, Ubuntu 18.04

@KevinThoriya
Copy link

same problem,
have to start manually both servers.
Ubuntu 18.04

@theilig
Copy link
Contributor

theilig commented Jun 9, 2020

heh I should have looked here before I ratholed trying to fix this.

It's weird because I can execute the same line in a standalone scala script and it works, but it doesn't seem to work in the sbt hook, so I really struggled to isolate exactly what caused the problem.

import sys.process._

object TestNpm extends App {
  val p = Process("npm start --prefix /Users/theilig/code/Test/ui").!
}

works from a totally different project/directory

however changing the hook to execute the same line at sbt run-time doesn't work

I suspect it's happening somewhere in the compile step, but even with verbose logging I couldn't see any errors

@theilig
Copy link
Contributor

theilig commented Jun 10, 2020

ok, starting to nail it down, it does not happen with react-scripts 3.2, unclear with 3.3 because that was broken. However I expect it has to do with

facebook/create-react-app@1cbc6f7

The timing lines up, and we seem to be dying around when the public url slice is happening

@theilig
Copy link
Contributor

theilig commented Jun 10, 2020

Actually
facebook/create-react-app@7e6d6cd

Looks like the change, verified that react 3.4.0 is fine, and 3.4.1 is not.

This change landed between them, and is almost certainly closing webpack because we are not interactive

theilig pushed a commit to theilig/scala-play-react-seed that referenced this issue Jun 10, 2020
…le command playframework#25

In react-scripts-3.4.1+ the run command will exit immediately
unless you indicate it should be run in "CI" mode.
@AlexTo
Copy link

AlexTo commented Jun 12, 2020

the above fix by @theilig works, thanks 👍

@ptrdom
Copy link
Member

ptrdom commented Jan 22, 2021

Maybe it would make sense to downgrade to react-scripts 3.4.0 in master branch? I bet that everyone is bothered by this issue.

@ptrdom
Copy link
Member

ptrdom commented Apr 23, 2022

Closed by #30.

@ptrdom ptrdom closed this as completed Apr 23, 2022
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

9 participants