httptoolkit / httptoolkit-ui

The UI of HTTP Toolkit
https://httptoolkit.com
GNU Affero General Public License v3.0
288 stars 107 forks source link

`npm start` doesn't work on Windows #59

Closed lord-ne closed 1 year ago

lord-ne commented 1 year ago

I was trying to compile/run this repo following the instructions in the README, but I'm getting a lot of errors that I'm not sure how to deal with. I'm not sure exactly what I'm doing wrong.

I'm on Windows. I cloned the repo and ran npm install.

Running npm start yields:

> httptoolkit-ui@0.1.0 start
> ./node_modules/httptoolkit-server/bin/run start & npm run start:web

'.' is not recognized as an internal or external command,
operable program or batch file.

> httptoolkit-ui@0.1.0 start:web
> env-cmd -f ./automation/ts-node.env webpack-dev-server --config ./automation/webpack.dev.ts

i 「wds」: Project is running at http://local.httptoolkit.tech:8080/
i 「wds」: webpack output is served from /
i 「wds」: Content not from webpack is served from C:\Users\Noam\Desktop\httptoolkit-ui-master\dist
i 「wds」: 404s will fallback to /index.html
i 「wdm」: Hash: 9685bf8b84bc1511f2ab
Version: webpack 4.46.0
Time: 33958ms
Built at: 11/08/2022 3:27:59 PM
i 「wdm」: Compiled successfully.
No issues found.

When opening the actual local.httptoolkit.tech:8080 site in the browser (Firefox), it displays the "This is taking longer than normal" message, and a whole bunch and a bunch of errors appear in the console, including the following:

Error messages ``` Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:45456/start. (Reason: CORS request did not succeed). Status code: (null). ``` ``` proxy-store.ts:55 Server initialization failed TypeError: NetworkError when attempting to fetch resource. ``` ``` index.tsx:66 Service worker not supported, oh well, no autoupdating for you. ``` ``` index.tsx:129 Previous server version was null ``` ``` errors.ts:55 Reporting error: Error: Failed to initialize application index.tsx:131 fulfilled index.tsx:31 promise callback*step index.tsx:33 __awaiter index.tsx:34 __awaiter index.tsx:30 index.tsx:128 promise callback* index.tsx:128 tsx app.js:27449 __webpack_require__ app.js:105 0 app.js:28277 __webpack_require__ app.js:105 app.js:275 app.js:278 ```

So it seems like the server isn't being run because of the first error, and I would then assume that all of the browser console errors are because the server isn't running. The error '.' is not recognized as an internal or external command, operable program or batch file. seems to indicate that this repo isn't set up to be run on Windows. Do I need to develop on Linux?

lord-ne commented 1 year ago

I was able to get it to work with the npm-run-all module, adding the following to package.json:

    "server-start": "node node_modules/httptoolkit-server/bin/run start",
    "start": "npm-run-all --parallel server-start start:web",

Looking into it further, basically none of the scripts in package.json are cross-platform, so I guess the answer is just don't use Windows.

lord-ne commented 1 year ago

On second thought, I'll reopen this, just so the dev can confirm that I'm understanding correctly

pimterry commented 1 year ago

Yes, that's fair. Technically it's not a Windows problem: the current setup just assumes a POSIX shell, which means it'll work in effectively all shells on Linux & Mac, and it can work on Windows, but only works if you're using Git Bash/Cygwin/etc. Regardless, the end result is that running it in a normal Windows cmd terminal won't work, yes.

This is a good suggestion, we should fix this. Can you open a PR to switch to npm-run-all with a replacement that works for you?

lord-ne commented 1 year ago

Sounds good. I'll do a bit more work to try and get all the commands working, not just start, before I open one.