webpack-dev-server icon indicating copy to clipboard operation
webpack-dev-server copied to clipboard

Anyone here got webpack-dev-server to work on Cloud 9?

Open YarivGilad opened this issue 11 years ago • 30 comments

Hi, since webpack-dev-server has a dependency on node-gyp ( see issue #229 ) we tried using it with cloud 9 which runs an online editor on a Linux machine. The installations of webpack-dev-server on cloud 9 goes smoothly but requests to it were not successful. I suspect it has something to do with a different networking paradigm. All the tutorials I've found on webpack-dev-server show the index.html will have a script tag with the source of the output bundle.js coming from the webpack-dev-server at localhost:8080 which is the default... when you run on your local machine it make sense to access the server via localhost, but when you run the webpack-dev-server on cloud 9 it should be something else. a normal express app could be accessible via their scheme - https:// + your username + / + your workspace name - serving as if you would run localhost, so I tried that scheme and it didn't work, I tried using 0.0.0.0:8080 and it didn't work. I also noticed that c9 runs on https and the webpack-dev-server must assume plain http when communicating with the client via socket.io... In short - I'd appreciate any help from someone who managed to get the webpack-dev-server to run on c9... Thanks Ajar

YarivGilad avatar Jul 31 '15 05:07 YarivGilad

This might help. Assuming you want to use react-hot-loader.

webpack-dev-server  --host $IP --port $PORT  --hot --inline

Browse at https://workspace-user.c9.io/webpack-dev-server/

manavsehgal avatar Aug 02 '15 10:08 manavsehgal

webpack-dev-server --port $PORT --host $IP  --content-base build/

works for me

mvhenten avatar Feb 24 '16 21:02 mvhenten

Hot reloading isn't working for me. My site comes up at https://react-tsongas.c9.io/ however in the browser console I'm getting repeated errors that make it look like hot reload is trying to happen over http rather than https and getting blocked:

abstract-xhr.js?96d9:128 Mixed Content: The page at 'https://react-tsongas.c9.io/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://react-tsongas.c9.io:8080/sockjs-node/info?t=1461778636613'. This request has been blocked; the content must be served over HTTPS.

Any ideas how to solve this? I wonder if it's related to this webpack-dev-server bug? https://community.c9.io/t/mixed-content-with-webpack-dev-server/3053

tsongas avatar Apr 27 '16 17:04 tsongas

As per https://community.c9.io/t/mixed-content-with-webpack-dev-server/3053/4 you can go to your node_modules/webpack-dev-server/client/index.js and replace line 62 protocol: urlParts.protocol, with protocol: (window.location.protocol == 'https:') ? 'https:' : urlParts.protocol,

After this, you should be able to run dev server with cli, without the --https flag. (I couldn't get it to work with the flag, I get 'ECONNRESET: Request could not be proxied!' and 'There was an error proxying the request.')

I don't know enough to judge whether this applies to C9 or other https servers in general, and I wonder if anyone should do a pull request on this..?

joonhyublee avatar May 08 '16 08:05 joonhyublee

There's an open pull request https://github.com/webpack/webpack-dev-server/pull/470 maybe someone can rattle the chain of the maintainer?

tsongas avatar May 08 '16 08:05 tsongas

I was having this problem too on cloud9. After playing around with it for awhile, I got hot reloading on cloud9 to work with webpack-dev-server 1.14.1 without any patches.

The key change I made was creating webpack-dev-server/client?https://0.0.0.0:8080 as an entry point.

Running webpack-dev-server --host $IP --port $PORT runs my application with hot reloading.

Here's the full webpack.config.js:

var webpack = require('webpack');

const path = require('path');

module.exports = {
    "entry": [
        'webpack-dev-server/client?https://0.0.0.0:8080',
        'webpack/hot/only-dev-server',
        './app/index.js'
    ],
    "output": {
        "path": path.join(__dirname, 'build'),
        "filename": "bundle.js"
    },
    devtool: "source-map",
    "module": {
        "loaders": [
            {
                "test": /.js?$/,
                "loader": 'react-hot!babel-loader',
                "exclude": /node_modules/
            },
            {
                "test": /\.scss$/,
                "loaders": ["style", "css?sourceMap", "sass?sourceMap"]
            } 
        ]
    },
    devServer: {
        contentBase: './build',
        hot: true
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin()
    ]
};

emckay avatar May 11 '16 20:05 emckay

Can't get it working as described. Works only for me in c9 with patching as mentioned by @joonhyublee

teamgroove avatar Jun 11 '16 21:06 teamgroove

For a working example, you can clone this bare-bones react boilerplate repository: https://github.com/eloquently/react-boilerplate .

npm install and npm run webpack-dev-server should run the application (master branch is configured for Cloud9).

Change something in the App component, and you should see the HMR working.

emckay avatar Jun 13 '16 04:06 emckay

Ok. i will try again tomorrow. i will get back. Thank you.

teamgroove avatar Jun 16 '16 23:06 teamgroove

You are right, this configuration works in cloud9 without any mods to: client.js. I'm investigation what the difference actually is.

teamgroove avatar Jun 17 '16 20:06 teamgroove

It was completely my fault. I had some overrides in the webpack.config.babel.js for the entry-point, ENV-vars and mcuh more. After fixing my errors - everything runs smoothely. Thanks for the helpful hint!

teamgroove avatar Jun 17 '16 22:06 teamgroove

Glad you got it working!

emckay avatar Jun 18 '16 15:06 emckay

Hey here's another option if just looking for the essentials: blank-merrn-c9. Check out the webpack.dev.config.js and package.json to see what it's using.

slmoore avatar Jul 28 '16 21:07 slmoore

Closing because it seems to be working :).

SpaceK33z avatar Aug 25 '16 16:08 SpaceK33z

@emckay thanks, it works for me :)

cifren avatar Nov 22 '16 11:11 cifren

1.In order to get it working, I went into the file that the npm start script calls, "./node_modules/webpack-dev-server/bin/webpack-dev-server.js"

  1. go to node_modules/webpack-dev-server/bin/webpack-dev-server.js file. Line 209, the listen method

  2. change options.host and options.port to process.env.IP and process.env.PORT. Now u can run it. YAY!

AndrewNgKF avatar Feb 06 '17 15:02 AndrewNgKF

@AndrewNgKF That worked for me thanks a bunch!

codersc avatar Feb 07 '17 06:02 codersc

i did all of the things posted here included the last one (modifcation of webpack-dev-server.js) and i cant make work , i got on browser console [WDS] Disconnected! , i will appreciate you help .

Thanks

emacreative avatar Apr 27 '17 15:04 emacreative

In webpack.config.js:

devServer: { historyApiFallback: true, contentBase: './', host: process.env.IP, //https: true, port: process.env.PORT, "public": "your-project.c9users.io" //no trailing slash }

adleviton avatar May 02 '17 05:05 adleviton

i did all of the things posted here too... does not work!

pelx avatar Jun 12 '17 16:06 pelx