Webpack-dev-server: unable open "http://localhost:port" page

Created on 15 Apr 2021  路  12Comments  路  Source: webpack/webpack-dev-server

  • Operating System: Win10
  • Node Version: 12.16.3
  • NPM Version: 6.14.4
  • webpack Version: 5.32.2
  • webpack-dev-server Version:4.0.0-beta.2
  • Browser: chrome 89.0.4389.114

  • [ x] This is a bug

Code

// webpack.config.js
{
    devServer:{
        host:'local-ipv4',
        open:{
            target:`http://localhost:5000/`
        },
        port:5000
    }
}
// additional code, remove if not needed.

Expected Behavior

open a new page with http://localhost:5000

Actual Behavior

log "unable to open 'http://localhost:5000/' page ..."

All 12 comments

Set target: true

Set target: true

not work

I am unable to reproduce, please share a reproduction repo.

See more on --open-target usage here - https://github.com/webpack/webpack-dev-server/tree/master/examples/cli/open-target#cli-open-target-option

Hi @mahuiplus, local-ipv4 and localhost are on different addresses therefore your config should not work. If you want to open on 'localhost' as well as on LAN, try default settings for host:

{
    devServer:{
        open: true,
        port:5000
    }
}

Ah yes, different host addresses. target: true still should have worked though 馃槙 .

Ah yes, different host addresses. target: true still should have worked though .

target: true with host: 'local-ipv4' will not open on http://localhost:5000/ as OP wanted.

I logger the exception

Hi @mahuiplus, local-ipv4 and localhost are on different addresses therefore your config should not work. If you want to open on 'localhost' as well as on LAN, try default settings for host:

{
    devServer:{
        open: true,
        port:5000
    }
}

set 'open: true' not work too

Works for me, can you provide error log / reproducible repo? Also, have you removed host: 'local-ipv4'?

debug in 'webpack-dev-server/lib/utils/runOpen.js'

logger.warn(`openTarget:${openTarget}`)

logger.warn(`openTask:${openTask}`) 

return open(openTarget, openTask.options).catch((e) => {  
    logger.warn(e)  
    logger.warn(    `Unable to open "${openTarget}" page${  
    ...

here is the error log

<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:5000/
<i> [webpack-dev-server] Content not from webpack is served from 'D:\Project\lr15-04_bds_web_management\app\images, D:\Project\lr15-04_bds_web_management\app\_commons\images' directory
<i> [webpack-dev-server] 404s will fallback to '/index.html'
<w> [webpack-dev-server] openTarget:http://localhost:5000/
<w> [webpack-dev-server] openTask:[object Object]
<w> [webpack-dev-server] Error: spawn EPERM
<w>     at ChildProcess.spawn (internal/child_process.js:407:11)
<w>     at Object.spawn (child_process.js:548:9)
<w>     at module.exports (D:\Project\lr15-04_bds_web_management\node_modules\open\index.js:175:34)
<w>     at async Promise.all (index 0) {
<w>   errno: 'EPERM',
<w>   code: 'EPERM',
<w>   syscall: 'spawn'
<w> }
<w> [webpack-dev-server] Unable to open "http://localhost:5000/" page. If you are running in a headless environment, please do not use the "--open" flag or the "open" option.

something wrong with open?

the same code & node version, It works on my mac...

I have to open it manually on my win10...

That makes sense, I am on linux and works there.

you don't have permission to open, here message spawn EPERM, check your local permissions, you can try to run in console chrome or other default browser

Was this page helpful?
0 / 5 - 0 ratings