Unable to start webpack-dev-server

Running bin/webpack-dev-server does not recognize hyphens.
Do you have any suggestions for improvement?

render@xxxxxx:~/project/src$ bin/webpack-dev-server 
webpack dev_server configuration not found in /opt/render/project/src/config/webpacker.yml[production].
Please run bundle exec rails webpacker:install to install Webpacker

Hi.

It looks like the error is telling you that you don’t have a dev_server: config in your webpacker.yml file.

When you run webpack-dev-server in a Rails project, it looks for the dev_server: configuration in webpacker.yml. The keys/values map to webpacker-dev-server settings.

Take a look at your webpacker.yml file and confirm you have a dev_server: config present. Here is an example of a default (I don’t believe I made any changes) config:

# Reference: https://webpack.js.org/configuration/dev-server/
  dev_server:
    https: false
    host: localhost
    port: 3035
    public: localhost:3035
    hmr: false
    # Inline should be set to true if using HMR
    inline: true
    overlay: true
    compress: true
    disable_host_check: true
    use_local_ip: false
    quiet: false
    pretty: false
    headers:
      'Access-Control-Allow-Origin': '*'
    watch_options:
      ignored: '**/node_modules/**'

Also, you’ll want to make sure you are not running webpack-dev-server in production. It is a development tool to allow hot reloading, not something that should be running in a production app. Cheers!

Hi.

I read your responses before you deleted them. Your dev_server configuration looked fine. I loaded it in my local dev environment and was able to launch webpack-dev-server without issue.

The issue appears to be that your Rails environment in render is your production environment.

‘dev_server:’ is defined in the ‘development:’ area of your webpacker.yml file. When you run webpack-dev-server in Development, it will look to your ‘dev_server:’ config.

If you attempt to run webpack-dev-server in your Rails production environment it will looks for the ‘dev_server:’ config within ‘production:’, where it doesn’t and generate the error your received (of no dev_server config).

You might be able to copy your dev_server config into the production: area of your webacker.yml file, but you should not be running wepack-dev-server in a production environment.

1 Like