Unknown WebSocket (SockJS) on Google App Engine - google-app-engine

I've deployed a React app running on NodeJS to the google app engine and everything works well. However, when I load the main page, I get a WebSocket error (failed handshake) that occurs 15s later, probably due to a timeout. The thing is, I don't use SockJS in my app at all so I suspect the app engine makes use of it. Note that this error happens both while loading through HTTP and HTTPS.
It does not break anything but the user can see that the browser is waiting for the page to load entirely, which is bothering.
Why is this socket used? Can I turn it off?
Here is the error stack:
websocket.js:6 WebSocket connection to 'wss://*****.appspot.com/sockjs-node/514/vrdqxoct/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400
WebSocketBrowserDriver # websocket.js:6
WebSocketTransport # websocket.js:32
./node_modules/sockjs-client/lib/main.js.SockJS._connect # main.js:219
./node_modules/sockjs-client/lib/main.js.SockJS._receiveInfo # main.js:193
g # emitter.js:30
./node_modules/sockjs-client/lib/event/emitter.js.EventEmitter.emit # emitter.js:50
(anonymous) # info-receiver.js:67
g # emitter.js:30
./node_modules/sockjs-client/lib/event/emitter.js.EventEmitter.emit # emitter.js:50
(anonymous) # info-ajax.js:37
g # emitter.js:30
./node_modules/sockjs-client/lib/event/emitter.js.EventEmitter.emit # emitter.js:50
xhr.onreadystatechange # abstract-xhr.js:124
EDIT:
As requested, here is my package.json and webpack.config.js.
package.json
{
"name": "*****",
"version": "0.1.0",
"private": true,
"dependencies": {
"bcryptjs": "^2.4.3",
"connected-react-router": "^4.3.0",
"jsonwebtoken": "^8.3.0",
"prop-types": "^15.6.1",
"react": "^16.4.1",
"react-apollo": "^1.4.16",
"react-copy-to-clipboard": "^5.0.1",
"react-dom": "^16.4.1",
"react-redux": "^5.0.7",
"react-router-dom": "^4.3.1",
"react-router-redux": "^4.0.8",
"react-scripts": "1.0.13",
"redux": "^3.7.2",
"redux-form": "^7.4.0",
"redux-logger": "^3.0.6",
"redux-middleware": "^0.1.21",
"redux-thunk": "^2.3.0",
"semantic-ui": "^2.3.1",
"semantic-ui-css": "^2.3.1",
"semantic-ui-less": "^2.3.1",
"semantic-ui-react": "^0.73.1",
"webpack": "^3.12.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"deploy": "gcloud app deploy"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-register": "^6.26.0",
"file-loader": "^0.11.2",
"font-loader": "^0.1.2",
"gulp": "^3.9.1"
}
}
webpack.config.js
import path from 'path';
export default {
devtool: 'eval',
entry: './src/index',
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/',
},
module: {
rules: [{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.js$/,
use: ['babel-loader'],
exclude: /node_modules/,
include: __dirname
},
{
test: /\.(png|svg|jpg|gif)$/,
use: ['file-loader']
}
]
}
};
Thanks.

Like I mentioned in the comments, this is due to webpack.
This is the script that runs for react-scripts start start script.
If you look at the code, it internally uses webpack-dev-server. If you find the default config for webpack-dev-server (here), the default config has HOT RELOADING enabled by default. Hence you see socket connections created to enable HOT RELOADING.

Related

Duplicated React/Redux project resulting "async_hooks" not found

First of all, thank you all for your attention. I'm new about react/redux code, and I have an old project that already existed and I only need to duplicate it because they need the same version with some different parameters.
So, I duplicated the old project, created a new gitlab project for it, changed what I needed(practically only text) on the duplicated project, then how it was showing many errors after "npm run build", I did:
Inside the package.json file I changed "node-sass" to use the version 4.11.0 because the old one was generating some "Module not found: Error: Cannot resolve module" kind of errors(as I said, this was a duplication from a old project that even is still running on production has many deprecated dependencies).
I deleted the package-lock.json file.
I deleted also the node_modules folder.
I did "npm install" already on the master branch of the folder to create again the node_modules.
As you can see, I just tried to delete the package-lock.json file then I deleted the node_modules folder, and finally I did "npm install", but when I tried "npm run build", the async_hooks error showed up... I'm stuck in this part.
After these basic steps, the error happened: Cannot resolve module 'async_hooks'. I tried to "npm install async_hooks" but it didn't work, I also tried to put the "async-hooks" on the package.json file but it didn't work, and finally I also tried put a new version from bluebird there but didn't work too.
How to install this "async_hooks"? Because even after doing "npm install async_hooks" it didn't work yet. I run "npm run build" but the same error happened.
See below the full result:
Module not found: Error: Cannot resolve module 'async_hooks' in C:\xampp\htdocs\careers\node_modules\bluebird\js\release
# ./~/bluebird/js/release/util.js 410:18-40
ERROR in ./~/bluebird/js/release/promise.js
Module not found: Error: Cannot resolve module 'async_hooks' in C:\xampp\htdocs\careers\node_modules\bluebird\js\release
# ./~/bluebird/js/release/promise.js 34:4-26
. Here is my package.json file:
"main": "index.js",
"repository": "git#github.com:StephenGrider/ReduxSimpleStarter.git",
"scripts": {
"start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
"build": "node ./node_modules/webpack/bin/webpack.js ",
"test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
"test:watch": "npm run test -- --watch"
},
"license": "ISC",
"engines": {
"node": "^v8.9.4"
},
"devDependencies": {
"babel-core": "^6.2.1",
"babel-eslint": "^6.1.2",
"babel-loader": "^6.2.4",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-react-transform": "^2.0.2",
"babel-plugin-transform-react-constant-elements": "^6.3.13",
"babel-plugin-transform-react-inline-elements": "^6.3.13",
"babel-plugin-transform-runtime": "^6.12.0",
"babel-polyfill": "^6.9.1",
"babel-preset-es2015": "^6.1.18",
"babel-preset-es2015-node5": "^1.2.0",
"babel-preset-react": "^6.1.18",
"babel-preset-react-hmre": "^1.1.1",
"babel-preset-stage-1": "^6.1.18",
"babel-register": "^6.11.6",
"babel-runtime": "^6.11.6",
"bootstrap-loader": "^1.1.0-beta.1",
"bootstrap-sass": "^3.3.7",
"chai": "~3.5.0",
"chai-jquery": "~2.0.0",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.9.0",
"jquery": "~2.2.1",
"jsdom": "~8.1.0",
"mocha": "~2.4.5",
"node-sass": "^4.11.0",
"postcss-loader": "^0.9.1",
"react-addons-test-utils": "~0.14.7",
"resolve-url-loader": "^1.6.0",
"sass-loader": "^3.2.0",
"style-loader": "^0.13.1",
"url-loader": "^0.5.7",
"webpack": "~1.12.9",
"webpack-dev-server": "~1.14.0"
},
"dependencies": {
"axios": "~0.13.1",
"bluebird": "^3.4.1",
"css-loader": "^0.23.1",
"griddle-react": "~0.6.0",
"immutable": "^3.8.1",
"jwt-decode": "^2.2.0",
"lodash": "~3.10.1",
"moment": "^2.19.1",
"nested-property": "^0.0.7",
"numeral": "^2.0.6",
"react": "^0.14.3",
"react-datetime": "^2.10.3",
"react-dom": "^0.14.3",
"react-ga": "^2.3.5",
"react-redux": "~4.3.0",
"react-router": "~2.0.1",
"redux": "~3.1.7",
"redux-form": "^6.1.1",
"redux-logger": "^3.0.1",
"redux-thunk": "^2.2.0"
}
}
. and here is my webpack.config.js file:
var path = require('path');
module.exports = {
entry: [
'./src/index.js'
],
output: {
path: path.join(__dirname,'./js/'),
publicPath: '/js/',
filename: 'bundle.js'
},
module: {
loaders: [{
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['react', 'es2015', 'stage-1']
}
}]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
devServer: {
historyApiFallback: true,
contentBase: './'
}
};
Any ideas?

502 bad gateway while deploying stand alone webpack + react application on google cloud engine (no server)

I created a react application with webpack and am trying to deploy it to google app engine. There is no server to this application, everything is done in the browser. I have successfully deployed simple react apps previously but I think the webpack entry points is what is causing me headaches at the moment.
My application gets deployed successfully, but when navigating to the URL, I get a 502 bad gateway error. When looking at $gcloud app logs read, I see no issues, my app is compiled and built successfully, and none of the logs in the google cloud console are helpful either. I've tried moving all my devDependencies to dependencies.
My webpack config:
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: './src/index.js',
mode: 'development',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
options: {
presets: [
'#babel/env'
]
}
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.(png|svg|otf)$/,
loader: 'file-loader',
options: {
name: '[path][name].[ext]'
}
}
]
},
resolve: {
extensions: ['*', '.js', '.jsx']
},
output: {
path: path.resolve(__dirname, 'dist/'),
publicPath: '/dist/',
filename: 'bundle.js'
},
devServer: {
contentBase: path.join(__dirname, 'public/'),
port: 8080,
publicPath: 'http://localhost:8080/dist/',
hot: true
},
devtool: "source-map",
plugins: [new webpack.HotModuleReplacementPlugin()]
};
app.yaml:
# [START app_yaml]
env: flex
runtime: nodejs
# [END app_yaml]
package.json:
{
"name": "my-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server --mode development",
"build": "webpack --config webpack.config.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.1.0",
"#babel/core": "^7.1.0",
"#babel/preset-env": "^7.1.0",
"#babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.2",
"css-loader": "^1.0.0",
"d3": "^5.11.0",
"file-loader": "^4.2.0",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-masonry-css": "^1.0.12",
"style-loader": "^0.23.0",
"webpack": "^4.19.1",
"webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.8.0"
},
"dependencies": {
"bootstrap": "^4.3.1",
"react-hot-loader": "^4.3.11",
"webpack-dev-server": "^3.8.0",
"webpack": "^4.19.1",
"webpack-cli": "^3.1.1",
"#babel/cli": "^7.1.0",
"#babel/core": "^7.1.0",
"#babel/preset-env": "^7.1.0",
"#babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.2",
"css-loader": "^1.0.0",
"d3": "^5.11.0",
"file-loader": "^4.2.0",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-masonry-css": "^1.0.12",
"style-loader": "^0.23.0"
}
}
If all is properly set up, one of the possible causes is scalability. If it is not a scalability issue, do you have any support package/free trial? I'd recommend you to open a support ticket directly in the support center, if not you can contact Google through Google Issue Tracker as 5XX errors can be caused by different reasons, therefore very hard to troubleshoot from SO.

Stuck on Setting Up Webpack with React

I've tried looking at the docs and searching online, but I'm having a really hard time configuring webpack with my React project. I'm trying to use webpack-dev-server. When I do the yarn start command, this is what I see in the browser.
Image of what I see in the browser
I have no idea where to go from here. This is what my webpack.config.js looks like.
const path = require("path");
module.exports = {
entry: './src/components/app.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
devServer: {
contentBase: "./dist"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader'
}
]
}
};
Here is my package.json
{
"name": "react-portfolio",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-router-dom": "^4.2.2",
"react-scripts": "1.1.1",
"source-map-explorer": "^1.5.0"
},
"scripts": {
"analyze": "source-map-explorer build/static/js/main.*",
"start": "webpack-dev-server --open",
"build": "webpack",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.3",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"webpack": "^4.0.1",
"webpack-cli": "^2.0.9",
"webpack-dev-server": "^3.1.0"
}
}
Any guidance would be greatly appreciated.

React webpack bundle for production

I need some help to bundle my output for production but I have no idea how. Here's my webpack.config.js
module.exports = {
devtool: 'eval',
context: __dirname,
entry: "./js-source/index.jsx",
output: {
path: __dirname + "/scripts",
filename: "bundle.js"
},
module: {
loaders: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
exclude: /node_modules/
}
],
resolve: {
extensions: ['', '.js', '.jsx', '.json']
}
}
};
Here's my package.json
{
"name": "citygross-store-web",
"version": "2.0.0",
"dependencies": {
"axios": "^0.14.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-redux": "^4.1.2",
"react-responsive": "^1.3.0",
"react-router": "^4.1.1",
"react-router-dom": "^4.1.1",
"react-transition-group": "^1.2.0",
"redux": "^3.1.2",
"redux-logger": "^2.6.1",
"redux-promise-middleware": "^4.0.0",
"redux-thunk": "^2.1.0"
},
"devDependencies": {
"babel-core": "^6.21.0",
"babel-loader": "^6.2.10",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.24.1",
"babel-preset-latest": "^6.16.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.24.1",
"babel-preset-stage-1": "^6.24.1",
"babel-preset-stage-2": "^6.13.0",
"webpack": "^1.14.0",
"webpack-hot-middleware": "^2.12.2"
},
"scripts": {
"build": "webpack --colors",
"dev": "webpack --watch --colors"
},
"-vs-binding": {
"ProjectOpened": [
"dev"
]
}
}
How do you usually bundle for production? By adding a command like "npm run build" and having the other settings in that setting?
I would appreciate if someone could help me out how to set this up. Right now I can do "npm run dev" and "npm run build", however there's no difference between using the two more than "run dev" creates a -watcher and build builds the bundle one time.
Set the environment variable NODE_ENV to production when running your build script. This will cause the production build of React to be included in the output.
Easiest way is to add another script to your package.json:
"scripts": {
"build": "webpack --colors",
"buildprod": "NODE_ENV=production webpack --colors",
"dev": "webpack --watch --colors"
},
Now when you do npm run buildprod, you'll get a production build of your code.
Note: if you are on Windows, the above won't work right. For proper cross-OS you should use cross-env:
Install cross-env:
npm install cross-env --save-dev
or
yarn add cross-env --dev
Then make your scripts section look like:
"scripts": {
"build": "webpack --colors",
"buildprod": "cross-env NODE_ENV=production webpack --colors",
"dev": "webpack --watch --colors"
},

Deploy React-Redux webpack on heroku

Well, Im having a big problem, I have a front-end only react that send request to a ruby on rails api, we use redux, babel and webpack. My problem is, I cant make this react project work on Heroku.
This is a 503 response error from heroku.
Package.json:
{
"name": "real-networking-ui",
"version": "1.0.0",
"description": "Real Netoworking UI",
"main": "index.js",
"scripts": {
"start": "node -r babel-register ./node_modules/webpack-dev-server/bin/webpack-dev-server --config ./webpack.config.dev.js --progress --profile --colors",
"build": "node -r babel-register ./node_modules/webpack/bin/webpack --config ./webpack.config.prod --progress --profile --colors",
"lint": "eslint app test *.js"
},
"engines": {
"node": "6.6.0"
},
"author": "",
"license": "ISC",
"devDependencies": {
"autoprefixer": "^6.3.6",
"babel-core": "^6.10.4",
"babel-eslint": "^6.1.0",
"babel-loader": "^6.2.4",
"babel-plugin-dev-expression": "^0.2.1",
"babel-plugin-lodash": "^3.2.11",
"babel-plugin-react-transform": "^2.0.2",
"babel-plugin-transform-remove-console": "^6.8.0",
"babel-plugin-transform-remove-debugger": "^6.8.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.11.1",
"babel-preset-react-hmre": "^1.1.1",
"babel-preset-react-optimize": "^1.0.1",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.9.0",
"classnames": "^2.2.5",
"css-loader": "^0.23.1",
"eslint": "^2.13.1",
"eslint-config-airbnb": "^9.0.1",
"eslint-import-resolver-webpack": "^0.3.2",
"eslint-loader": "^1.6.1",
"eslint-plugin-import": "^1.10.0",
"eslint-plugin-jsx-a11y": "^1.5.3",
"eslint-plugin-react": "^5.2.2",
"extract-text-webpack-plugin": "^1.0.1",
"html-webpack-plugin": "^2.21.0",
"json-loader": "^0.5.4",
"postcss-css-variables": "^0.5.1",
"postcss-loader": "^0.9.1",
"postcss-mixins": "^5.0.0",
"postcss-nested": "^1.0.0",
"postcss-partial-import": "^1.3.0",
"react-transform-hmr": "^1.0.4",
"style-loader": "^0.13.1",
"svg-react": "^1.0.9",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1"
},
"dependencies": {
"axios": "^0.15.3",
"core-js": "^2.4.1",
"css-loader": "^0.23.1",
"lodash": "^4.17.2",
"moment": "^2.17.1",
"node-sass": "^3.13.0",
"react": "^15.1.0",
"react-dom": "^15.1.0",
"react-hot-loader": "^3.0.0-beta.6",
"react-maskedinput": "^3.3.1",
"react-modal": "^1.6.4",
"react-redux": "^4.4.5",
"react-router": "^3.0.0",
"react-router-redux": "^4.0.5",
"react-select": "^1.0.0-rc.2",
"react-select-box": "^3.0.1",
"redux": "^3.5.2",
"redux-thunk": "^2.1.0",
"sass-loader": "^4.0.2",
"style-loader": "^0.13.1",
"svg-react": "^1.0.9",
"validator": "^6.2.0",
"whatwg-fetch": "^2.0.1"
},
"eslintConfig": {
"extends": "react-app"
},
"babel": {
"presets": [
"react-app"
]
}
}
webpack.config.base:
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
export default {
entry: './app/app.js',
output: {
path: './app/App/dist',
filename: '/bundle.js',
},
module: {
loaders: [
{
test: /\.json$/,
loader: 'json',
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('css!sass'),
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('css!sass'),
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.svg$/,
loader: 'babel?presets[]=es2015,presets[]=react!svg-react',
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './app/App/index.html',
}),
new ExtractTextPlugin('/app/App/css/default.css', {
allChunks: true,
}),
],
};
webpack.config.dev:
import webpack from 'webpack';
import baseConfig from './webpack.config.base';
const config = {
...baseConfig,
debug: true,
devtool: 'cheap-module-eval-source-map',
plugins: [
...baseConfig.plugins,
new webpack.HotModuleReplacementPlugin(),
],
devServer: {
colors: true,
historyApiFallback: true,
inline: true,
hot: true,
},
};
export default config;
webpack.config.prod.js:
import webpack from 'webpack';
import baseConfig from './webpack.config.base';
const config = {
...baseConfig,
plugins: [
...baseConfig.plugins,
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compressor: {
screw_ie8: true,
warnings: false,
},
}),
],
};
export default config;
Procfile:
web: npm start
If you need more information about that tell me that I edit it.
Thank you for the help.
The heroku default configuration is to cache the dependencies in node_modules and set production environment to true.
Caching node_modules prevents additional modules from getting installed.
Production Environment prevents devDependencies in package.json from getting installed.
Refer to this link to solve the above problems
Also, webpack-dev-server doesn't work in Heroku, so it's better to create a small web server (Personally I like Express server) to serve the dist folder and then deploy the app.
Additionally, If you are still facing the problem, try running heroku logs --tail and paste the logs here.
My take on this is the devDependencies should be re-installed under dependencies. Under similar circumstances I had the error screen when trying to deploy on Heroku. The devDependencies are ignored and whenever your code asks for them Heroku alarms.

Resources