Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Rewrite rules stopped working from npx on Windows #158

Closed
kenlyon opened this issue Dec 30, 2020 · 10 comments
Closed

Rewrite rules stopped working from npx on Windows #158

kenlyon opened this issue Dec 30, 2020 · 10 comments
Labels

Comments

@kenlyon
Copy link

kenlyon commented Dec 30, 2020

I'm running on windows 10. I used to be able to supply command-line parameters for rewrite rules but today I ran into problems.

Windows is interpreting the ">" character in the rewrite rule as being the option to redirect output to a separate file, like you would here:

dir > files.txt

The most basic case that shows this is:

npx ws -r "/a -> /b"

The response I get is "Access is denied." which is Windows complaining about trying to write to /b.

There doesn't seem to be a way to escape the > character, so I've opted to use a lws.config.js config file instead, which solves the problem.

I'd suggest adding something about this to your wiki, as the Rewrite tutorial only mentions Windows needing double quotes instead of single quotes while in my case none of the inline examples work. It'd help others avoid the troubleshooting I had to go through.

Otherwise, I think your module is really useful. Thanks for making it!

@75lb 75lb self-assigned this Mar 13, 2021
@75lb
Copy link
Member

75lb commented Mar 17, 2021

Hi, can you confirm which shell you are using? I just ran the following command in both Git Bash and cmd on Windows 10 - everything worked correctly, as expected..

$ ws -r "/here -> /there" --verbose
{ 'middleware.cors.config': {} }
{
  'middleware.rewrite.config': { rewrite: [ { from: '/here', to: '/there' } ] }
}
{ 'middleware.conditional-get.config': {} }
{
  'middleware.static.config': { hidden: true, root: 'z:\\' }
}
{ 'middleware.index.config': { icons: true } }

@kenlyon
Copy link
Author

kenlyon commented Mar 18, 2021

I think I was using crd.exe, although I likely used the default shell in vs code as well.

I noticed you’re not running it via npx. Could that be why it works for you?

@75lb
Copy link
Member

75lb commented Mar 18, 2021

It could be an issue with npx or other Windows shells, then..

If you're having npx issues, this should work as an alternative:

./node_modules/.bin/ws -r "/here -> /there" --verbose

Closing, as the issue is not with local-web-server itself..

@75lb 75lb closed this as completed Mar 18, 2021
@Venryx
Copy link

Venryx commented May 13, 2021

I had the same issue on Windows, but fixed it with the workaround @75lb suggested. (although I needed to use backslashes rather than forward slashes)

Example:

.\node_modules\.bin\ws -r "/here -> /there" --verbose

So it appears the npx utility is not correctly handling either the quotes or the arrow. May be worth linking to this thread in the readme, for Windows users.

@75lb 75lb removed their assignment May 13, 2021
@75lb 75lb added the upstream label May 13, 2021
@75lb
Copy link
Member

75lb commented May 13, 2021

Could you confirm which version of npm you are using? I think this npx issue may have been fixed by this npm v7.4.0 PR..

@75lb 75lb reopened this May 13, 2021
@Venryx
Copy link

Venryx commented May 13, 2021

Ah, I am using NPM v6.14.5; the PR does look like it might fix it.

Unfortunately I don't have the motivation to confirm that at this point. (I don't want to risk ruining something in my npm dependency trees)

Because I can't confirm the issue for the latest versions (and because the linked PR probably fixes it), I'm fine with this issue being reclosed unless/until someone else can confirm it's still present in NPM v7.4.0+. (since there's a workaround for now anyway)

@kenlyon
Copy link
Author

kenlyon commented May 13, 2021

Despite the fault apparently being with npx, I still think it's worth considering updating the documentation to either mention the workaround or a minimum supported version in Windows. For me, I'm happy enough to use the separate config file. I think it's more maintainable in my case anyway.

Thanks for your help.

@75lb
Copy link
Member

75lb commented May 13, 2021

@kenlyon can you confirm this is still an issue with the lastest npm? As i posted above, this issue was apparently fixed in npm v7.4.0..

@kenlyon
Copy link
Author

kenlyon commented May 14, 2021

@75lb I can confirm that it does indeed work. Based on the Previous Releases page for node/npm, I confirmed it was still an issue with node 15.51.1 / npm 7.3.0. However, the next release (node 15.6.0 / npm 7.4.0) worked fine.

It's not really a viable solution for my use case, though, because we're using the LTS version and it wouldn't be trivial to switch to the "Current" track at this time. As I mentioned above, I'm fine with using the separate config file.

In addition, I confirmed it's still a problem in the latest LTS version. (node 14.17.0 / npm 6.14.13)

@75lb
Copy link
Member

75lb commented May 14, 2021

@kenlyon ok, thanks for confirming.. I have added a note to the top of the rewrite tutorial as suggested and will leave this issue open for a while. 👍

@75lb 75lb changed the title Rewrite rules no longer work on command line in Windows Rewrite rules stopped working from npx on Windows May 14, 2021
@75lb 75lb closed this as completed Jul 8, 2021
@lwsjs lwsjs locked and limited conversation to collaborators Jul 8, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

3 participants