parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.38k stars 2.27k forks source link

Incorrect output when using environment PORT #3249

Open ppqn opened 5 years ago

ppqn commented 5 years ago

🐛 bug report

When setting the port using the environment variable PORT; parcel incorrectly reports that the port could not be used.

🎛 Configuration (.babelrc, package.json, cli command)

Command line:

set PORT=3000
node --max-old-space-size=8192 node_modules/parcel-bundler/bin/cli.js serve -d build/serve --no-autoinstall --cache-dir build/serve_cache src/*.html

Server running at http://localhost:3000 - configured port 3000 could not be used.

🤔 Expected Behavior

Expects parcel to report:

Server running at http://localhost:3000

😯 Current Behavior

Parcel reports:

Server running at http://localhost:3000 - configured port 3000 could not be used.

💁 Possible Solution

In src/Server.js

 let addon =
        server.address().port !== port
          ? `- ${logger.chalk.yellow(
              `configured port ${port} could not be used.`
            )}`
          : '';

server.address().port is a number port could be a string or a number; when specifying an environment PORT on Windows, it seems that port is a string

Adding a Number.parseInt to the port seems to fix the problem:

 let addon =
        server.address().port !== Number.parse(port)
          ? `- ${logger.chalk.yellow(
              `configured port ${port} could not be used.`
            )}`
          : '';

🌍 Your Environment

Software Version(s)
Parcel 1.12.3
Operating System Windows 10
BrockAtkinson commented 4 years ago

@ppqn @DeMoorJasper is there anything against me making a pull request to fix this?

While this message is inconsequential, it looks like my library is broken.

JwanKhalaf commented 4 years ago

This is occuring on my Windows 10 Pro too.

image

I need it to run on port 1234, but not matter what, I can't get it to. Even though port 1234 is not in use.

ppqn commented 4 years ago

@JwanKhalaf This is only an aesthetic bug, the port was opened successfully, but the bug output "configured port .... could not be used" regardless. I don't think your problem is the same; your problem is the port cannot be opened so it opened a random port.

JwanKhalaf commented 4 years ago

@ppqn I suspect you're right. Thank you.

JwanKhalaf commented 4 years ago

@BrockAtkinson should I create a new issue for my version of the problem? There isn't much online about this problem.

JwanKhalaf commented 4 years ago

This was the fix for me: https://stackoverflow.com/a/58457861/613605

callumgare commented 4 years ago

@ppqn This was annoying me so I've submitted a pull request :)