Incorrect output when using environment PORT
See original GitHub issue🐛 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 |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:7
Top Results From Across the Web
Why after setting value to environment variable PORT the ...
The output in the terminal is listening to port undefined . My OS is Windows. I tried solutions online, such as PORT=2000 node...
Read more >env variables from .env file are not set in docker compose file
I was typing the command "docker-compose up -d" in the wrong directory.
Read more >Working with Environment Variables in Node.js - Twilio
This code should output all environment variables that this Node.js ... Cloud hosts like Heroku or Azure, however, use the PORT variable to ......
Read more >Using Environment Variables in Node.js for App Configuration ...
Learn why experienced Node.js developers use environment variables for app config and secrets, including how to manage default values and ...
Read more >Cloud Foundry Environment Variables
Cloud Foundry allocates a port dynamically for each instance of the app, so code that obtains or uses the app port should refer...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ppqn This was annoying me so I’ve submitted a pull request 😃
This was the fix for me: https://stackoverflow.com/a/58457861/613605