I've built a Node/React/Webpack app and just deployed it. Everything works just like on localhost for my desktop (Ubuntu 16.04 with Chrome and Firefox) and from an Android Galaxy Core phone using Chrome, but on an iPhone 5S using Safari and Firefox I don't get anything except the name of the app showing up in the title of the tab.
I don't think it's a case of CSS messing with me - I tried to go directly to one of the internal pages and it didn't redirect me to the main page like it should have, so I think it isn't loading at all.
Are there any common gotchas with this? This is the second Node/React/Webpack app I've built, using pretty similar methods, and the first one did fine on everything.
Here is my package.json file - if there's anything else that would be helpful to see just ask.
{
"name": "last-minute",
"version": "1.0.0",
"description": "connect to others nearby for last-minute hanging out",
"main": "webpack.prod.js",
"engines": {
"node": "9.5.0",
"npm": "6.1.0"
},
"scripts": {
"test": "jest --config jest.config.json",
"start": "node server/server.js",
"build": "webpack --config webpack.prod.js",
"dev": "webpack --config webpack.dev.js --mode development && node server/server.js",
"light": "webpack --config webpack.light.js --mode development && node light-server/style-server.js"
},
"author": "Doug Sauve",
"license": "ISC",
"dependencies": {
"#babel/core": "^7.0.0-beta.44",
"#babel/preset-env": "^7.0.0-beta.44",
"#babel/preset-react": "^7.0.0-beta.44",
"#google/maps": "^0.4.6",
"babel-loader": "^8.0.0-beta.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"bcryptjs": "^2.4.3",
"css-loader": "^0.28.11",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"express": "^4.16.2",
"google-maps-react": "^2.0.2",
"jest": "^22.4.4",
"moment": "^2.22.1",
"mongoose": "^5.0.14",
"node-sass": "^4.9.1",
"nodemailer": "^4.6.5",
"normalize.css": "^8.0.0",
"raf": "^3.4.0",
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-geocode": "0.0.9",
"react-redux": "^5.0.7",
"react-test-renderer": "^16.0.0",
"redux": "^4.0.0",
"sass-loader": "^6.0.7",
"socket.io": "^2.1.0",
"style-loader": "^0.20.3",
"validator": "^10.2.0",
"webpack": "^4.4.1",
"webpack-cli": "^2.0.13",
"webpack-merge": "^4.1.2"
}
}
webpack.common.js
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: ['babel-polyfill', path.join(__dirname, `/src/main.js`)],
output: {
path: path.join(__dirname, `/public`),
filename: `bundle.js`
},
module: {
rules: [
{
test: /\.js$/,
exclude: [
path.join(__dirname, '/node_modules'),
],
use: {
loader: 'babel-loader',
options: {
presets: ['#babel/preset-env', '#babel/preset-react'],
plugins: [
['transform-class-properties', { 'spec': true }],
['transform-object-rest-spread']
]
}
}
}, {
test: /\.s?css$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'sass-loader' }
]
}
]
}
};
webpack.prod.js
const merge = require ('webpack-merge');
const webpack = require ('webpack');
const common = require ('./webpack.common.js');
module.exports = merge(common, {
mode: 'production',
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
});
It seems to be an issue on older versions of iOS, not sure what the breakpoint is.
Related
I have installed the template from Electron-vue and I'm experiencing an issue with specific websites. These websites work on Chrome and Edge, yet, fail to completely load in webview.
The following example is the whole setup of the view. The console of this show that Local Storage, Session Storage and IndexedDB only have an entry for the website faselhd but have no data inside. The Cookies has an entry for the website with this type of data fcuid
<webview id="webview_custom" :src="https://www.faselhd.co/" style="height: 100%"></webview>
As far as I understand, there is an issue saving the session of the website and it's working correctly on the normal browsers but cannot save the session in the webview.
I have tried using this policy in my index.ejs, but had no luck.
<meta http-equiv="Content-Security-Policy" content="script-src * 'unsafe-inline' 'unsafe-eval'">
Expected: The website loads and shows the content.
Currently: The website keeps refreshing because the session cannot be saved.
package.json
{
"name": "my-app",
"version": "1.0.0",
"author": "author",
"description": "description",
"license": null,
"main": "./dist/electron/main.js",
"scripts": {
"build": "node .electron-vue/build.js && electron-builder",
"build:dir": "node .electron-vue/build.js && electron-builder --dir",
"build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js",
"build:web": "cross-env BUILD_TARGET=web node .electron-vue/build.js",
"dev": "node .electron-vue/dev-runner.js",
"pack": "npm run pack:main && npm run pack:renderer",
"pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js",
"pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js",
"postinstall": ""
},
"build": {
"productName": "app-electron",
"appId": "com.username.app_electron",
"directories": {
"output": "build"
},
"files": [
"dist/electron/**/*"
],
"dmg": {
"contents": [
{
"x": 410,
"y": 150,
"type": "link",
"path": "/Applications"
},
{
"x": 130,
"y": 150,
"type": "file"
}
]
},
"mac": {
"icon": "build/icons/icon.icns"
},
"win": {
"icon": "build/icons/icon.ico"
},
"linux": {
"icon": "build/icons"
}
},
"dependencies": {
"axios": "^0.18.0",
"electron-context-menu": "^0.16.0",
"vue": "^2.5.16",
"vue-electron": "^1.0.6",
"vue-router": "^3.0.1",
"vue-tabs-chrome": "^0.5.1",
"vuetify": "^2.2.17",
"vuetify-loader": "^1.4.3",
"vuex": "^3.0.1",
"vuex-electron": "^1.0.0"
},
"devDependencies": {
"ajv": "^6.5.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-minify-webpack-plugin": "^0.3.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.26.0",
"cfonts": "^2.1.2",
"chalk": "^2.4.1",
"copy-webpack-plugin": "^5.1.1",
"cross-env": "^5.1.6",
"css-loader": "^0.28.11",
"deepmerge": "^4.2.2",
"del": "^3.0.0",
"devtron": "^1.4.0",
"electron": "^2.0.4",
"electron-builder": "^20.19.2",
"electron-debug": "^1.5.0",
"electron-devtools-installer": "^2.2.4",
"fibers": "^4.0.2",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.2.0",
"jquery": "^3.4.1",
"lodash": "^4.17.15",
"mini-css-extract-plugin": "0.4.0",
"multispinner": "^0.2.1",
"node-loader": "^0.6.0",
"node-sass": "^4.9.2",
"sass": "^1.26.3",
"sass-loader": "^7.3.1",
"style-loader": "^0.21.0",
"url-loader": "^1.0.1",
"vue-html-loader": "^1.2.4",
"vue-loader": "^15.2.4",
"vue-style-loader": "^4.1.0",
"vue-template-compiler": "^2.5.16",
"webpack": "^4.15.1",
"webpack-cli": "^3.0.8",
"webpack-dev-server": "^3.1.4",
"webpack-hot-middleware": "^2.22.2",
"webpack-merge": "^4.1.3"
}
}
You're using the default template electron-vue which it uses a very old Electron 2.0.1 and that is Chrome 61, Node 8.9.3, V8 6.1.534.41 which is quite outdated to properly support Local Storage and Session Storage. You need to update Electron to a newer version.
To your existing project
Update electron to 8.1.x by running yarn add electron (this will update electron to latest 8.1.1)
Open .electron-vue/webpack.renderer.config.js and at line 115 change HtmlWebpackPlugin configuration object to this:
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, '../src/index.ejs'),
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
},
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
nodeModules: false
}),
Open src/main/index.js and update/add BrowserWindow webPreferences options like this:
mainWindow = new BrowserWindow({
height: 563,
useContentSize: true,
width: 1000,
// Add these webPreferences options
webPreferences: {
nodeIntegration: true,
webviewTag: true
}
})
Add a webview to your renderer. I had to set <webview src="..."> insted of binding <webview :src="..."> like this:
<template>
<div id="app">
<!-- <router-view></router-view> -->
<webview id="webview_custom" src="https://www.faselhd.co/" style="height: 100%"></webview>
</div>
</template>
<script>
export default {
name: 'vue-electron-webview2'
}
</script>
<style>
/* CSS */
html, body, #app { height: 100% }
</style>
Now run the app using yarn dev and you'll be able to see the the web page properly.
All,
I am trying to include babel-plugin-proposal-class-properties in my code bundle, but I get the following error;
2020-01-07 08:19:31.593 [error][tid:NSOperationQueue 0x2817acc40 (QOS: UNSPECIFIED)][RCTCxxBridge.mm:414] Failed to load bundle(http://169.254.99.36:8081/index.bundle?platform=ios&dev=true&minify=false) with error:(index.js: Cannot find module 'babel-plugin-plugin-proposal-class-properties' from '/Users/bburch/Projects/systems/SystemsDockConfig'
- Did you mean "#babel/plugin-proposal-class-properties"? (null))
My .babelrc looks like;
{ "presets": [
"#babel/env",
"#babel/react", ], "plugins": ["proposal-class-properties",] }
I also have tried this syntax;
{
"presets": [
"#babel/preset-env",
"#babel/preset-react"
],
"plugins": ["#babel/plugin-proposal-class-properties"]
}
In either case, somehow the "plugin" part of the package name is being doubled and of course the module is not found when that happens.
My package.json;
{
"name": "SystemsDockConfig",
"version": "0.0.2",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"#babel/plugin-proposal-class-properties": "^7.7.4",
"#babel/plugin-syntax-object-rest-spread": "^7.7.4",
"#babel/preset-env": "^7.7.7",
"buffer": "^5.0.7",
"eslint": "^6.8.0",
"eventemitter3": "^4.0.0",
"native-base": "^2.13.8",
"react": "16.8.3",
"react-native": "0.59.10",
"react-native-ble-plx": "1.1.0",
"react-native-camera": "^1.0.0",
"react-native-router-flux": "^4.0.6",
"react-native-version-number": "^0.3.1",
"react-native-wheel-datepicker": "^2.1.8"
},
"devDependencies": {
"#babel/core": "^7.6.4",
"#babel/runtime": "^7.6.3",
"babel-jest": "^24.9.0",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.56.0",
"react-test-renderer": "16.8.3"
},
"jest": {
"preset": "react-native"
}
}
I suggest you change your .babelrc to babel.config.json and use{
make sure you install
npm i --save-dev #babel/plugin-proposal-class-properties
this should work
bable.config.json
{
"presets": ["#babel/preset-env", "#babel/preset-react"],
"plugins": [
"#babel/plugin-proposal-class-properties"
]
}
I keep getting this error:
error in ./node_modules/keytar/build/Release/keytar.node
Module parse failed: Unexpected character '�' (1:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
# ./node_modules/keytar/lib/keytar.js 1:13-52
# ./src/background.js
# multi ./src/background.js
I have background.js set as the main electron file in package.json because I'm using vue/vuetify with it which uses a main.js file as well.
{
"name": "project",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
},
"main": "background.js", // <------------------ see right here
"dependencies": {
"axios": "^0.19.0",
"core-js": "^3.4.3",
"jwt-decode": "^2.2.0",
"keytar": "^5.0.0",
"request": "^2.88.0",
"vue": "^2.6.10",
"vue-router": "^3.1.3",
"vuetify": "^2.1.0",
"vuex": "^3.1.2"
},
"devDependencies": {
"#vue/cli-plugin-babel": "^4.1.0",
"#vue/cli-plugin-eslint": "^4.1.0",
"#vue/cli-service": "^4.1.0",
"babel-eslint": "^10.0.3",
"electron": "^7.1.3",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"node-loader": "^0.6.0",
"sass": "^1.19.0",
"sass-loader": "^8.0.0",
"vue-cli-plugin-electron-builder": "^1.4.3",
"vue-cli-plugin-vuetify": "^2.0.2",
"vue-template-compiler": "^2.6.10",
"vuetify-loader": "^1.3.0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
},
"browserslist": [
"> 1%",
"last 2 versions"
]
}
Searching, it seems this happens when keytar is used in a renderer process. But background.js isn't a renderer process. Or am I missing something? I am completely new to electron.
I needed to mark keytar as external (as mentioned at https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/guide.html#native-modules)
// vue.config.js
module.exports = {
pluginOptions: {
electronBuilder: {
// List native deps here if they don't work
externals: ['keytar']
}
}
}
Once I did that it worked properly.
Run appropriate loader (source).
yarn add node-loader -D
// vue.config.js
configureWebpack: {
devtool: 'source-map',
module: {
rules: [
{ test: /\.node$/, loader: 'node-loader' }
]
}
}
client folder where the react code sitsI am Using react with ruby on rails, I have created a separate folder named client for react code on the root. but whenever I changed something in the react i have to go to the page and refresh it manually, is there any way where I can automatically refresh the page whenever I can make any change in the code?
If you are using create-react-app then it should be available through that package. If you are building your own environment with Webpack, you can use Hot Module Replacement. https://webpack.js.org/guides/hot-module-replacement/
Edit:
Here are some example files from a project I made containing relevant code.
Webpack
const webpack = require('webpack');
const { resolve } = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server',
resolve(__dirname, "src") + "/index.jsx"
],
output: {
filename: 'app.bundle.js',
path: resolve(__dirname, 'build'),
publicPath: '/'
},
resolve: {
extensions: ['.js', '.jsx']
},
devtool: '#source-map',
devServer: {
hot: true,
contentBase: resolve(__dirname, 'build'),
publicPath: '/'
},
module: {
rules: [
{
test: /\.jsx?$/,
enforce: "pre",
loader: "eslint-loader",
exclude: /node_modules/,
options: {
emitWarning: true,
configFile: "./.eslintrc.json"
}
},
{
test: /\.(png|gif|jp(e*)g|svg)$/,
use: {
loader: 'url-loader',
options: {
limit: 8000,
name: 'images/[hash]-[name].[ext]'
}
}
},
{
test: /\.jsx?$/,
loader: "babel-loader",
exclude: /node_modules/,
options: {
presets: [
["es2015", {"modules": false}],
"react"
],
plugins: [
"react-hot-loader/babel",
"styled-jsx/babel"
]
}
},
],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new HtmlWebpackPlugin({
template:'template.ejs',
appMountId: 'react-app-root',
title: 'Project Name',
filename: resolve(__dirname, "build", "index.html"),
}),
]
};
Mainly, the entry, devServer, module.plugins and plugins at the bottom have the hot reloading code.
package.json
{
"name": "project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server",
"lint": "eslint src/index.jsx src/**/*.jsx; exit 0",
"lint-fix": "eslint src/index.jsx src/**/*.jsx --fix; exit 0"
},
"repository": {
"type": "git",
"url": "url"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "url"
},
"homepage": "relevant-url",
"dependencies": {
"eslint": "^5.0.1",
"eslint-plugin-react": "^7.10.0",
"file-loader": "^1.1.6",
"npm": "^6.1.0",
"prop-types": "^15.5.10",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-router-dom": "^4.0.0",
"styled-jsx": "^2.2.7",
"url-loader": "^0.6.2"
},
"devDependencies": {
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"eslint-loader": "^2.0.0",
"html-webpack-plugin": "^2.29.0",
"react-hot-loader": "^3.0.0-beta.7",
"webpack": "^3.4.0",
"webpack-dev-server": "^2.5.0"
}
}
The hot reloading packages in the devDependencies
index.jsx
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App';
import { AppContainer } from 'react-hot-loader';
import { HashRouter } from 'react-router-dom';
const render = (Component) => {
ReactDOM.render(
<AppContainer>
<HashRouter>
<Component/>
</HashRouter>
</AppContainer>,
document.getElementById('react-app-root')
);
};
render(App);
/*eslint-disable */
if (module.hot) {
module.hot.accept('./components/App', () => {
render(App);
});
}
/*eslint-enable */
Notice the AppContainer component imported from react-hot-loader that wraps your app in ReactDOM.render. Also, sometimes eslint can interfere with hot reloading which is why it is disabled and then enabled again at the bottom of the file.
I hope this helps.
About a week ago my app was deploying fine to production, however now I am seeing
Uncaught Error: Cannot find module "./lib/bootstrap.loader!./no-op.js"
var path = require('path');
var webpack = require('webpack');
var config = module.exports = {
entry: [
'bootstrap-loader',
'./app/frontend/javascripts/main.js'
],
stats: {
// Configure the console output
colors: true,
modules: true,
reasons: true
},
progress: true,
keepalive: true,
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader', // 'babel-loader' is also a legal name to reference
query: {
presets: ['es2015', 'react']
}
}, {
test: /\.css$/,
loader: 'style!css'
},
{ test: /bootstrap-sass\/assets\/javascripts\//, loader: 'imports?jQuery=jquery' },
{ test: /\.png$/, loader: "url-loader?limit=100000" },
{ test: /\.jpg$/, loader: "file-loader" },
{ test: /\.woff$/, loader: "url-loader?limit=10000&minetype=application/font-woff" },
{ test: /\.(woff2?|svg)$/, loader: 'url?limit=10000' },
{ test: /\.(ttf|eot)$/, loader: 'file' }
]
},
output: {
path: './app/assets/javascripts/',
filename: 'bundle.js',
publicPath: '/assets/',
devtoolModuleFilenameTemplate: '[resourcePath]',
devtoolFallbackModuleFilenameTemplate: '[resourcePath]?[hash]',
},
resolve: {
extensions: ['', '.js', '.jsx'],
modulesDirectories: [ 'node_modules', 'bower_components' ],
},
plugins: [
new webpack.ResolverPlugin([
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin('.bower.json', ['main'])
]),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
}),
//new webpack.optimize.CommonsChunkPlugin('common-bundle.js'),
//new webpack.optimize.CommonsChunkPlugin('public-bundle.js')
]
};
My package.json
"devDependencies": {
"babel-core": "~6.4.0",
"babel-loader": "~6.2.1",
"babel-preset-es2015": "~6.3.13",
"babel-preset-react": "~6.3.13",
"exports-loader": "~0.6.2",
"expose-loader": "~0.6.0",
"grunt": "~0.4.5",
"grunt-babel": "~6.0.0",
"grunt-cli": "~0.1.13",
"grunt-contrib-watch": "~0.6.1",
"grunt-webpack": "~1.0.11",
"history": "~1.17.0",
"imports-loader": "~0.6.3",
"jquery": "~2.1.4",
"lodash": "~3.0.0",
"react": "~0.14.6",
"react-dom": "~0.14.6",
"webpack": "~1.12.10",
"webpack-dev-server": "~1.14.0"
},
"dependencies": {
"autoresponsive-react": "^1.1.10",
"bluebird": "~3.1.1",
"bootstrap": "~3.3.6",
"bootstrap-loader": "~1.0.3",
"bootstrap-sass": "~3.3.6",
"bootstrap-webpack": "0.0.5",
"chunk-manifest-webpack-plugin": "0.0.1",
"classnames": "^2.2.3",
"css-loader": "~0.23.1",
"extract-text-webpack-plugin": "~1.0.1",
"file-loader": "~0.8.5",
"grunt-react": "~0.12.3",
"less": "~2.5.3",
"less-loader": "~2.2.2",
"node-sass": "~3.4.2",
"react-bootstrap": "~0.28.1",
"react-dropzone": "~3.3.2",
"react-grid-layout": "^0.10.0-beta1",
"react-image-component": "^1.0.0",
"react-input-autosize": "^0.6.6",
"react-modal-dialog": "^2.0.0",
"react-responsive": "^1.1.0",
"react-router": "~2.0.0-rc4",
"react-router-component": "~0.29.0",
"react-select": "^0.9.1",
"react-spinjs": "^2.0.1",
"react-swipe": "^3.0.0",
"reflux": "~0.3.0",
"reflux-core": "^0.3.0",
"reflux-promise": "^1.0.2",
"resolve-url-loader": "~1.4.3",
"sass-loader": "~3.1.2",
"style-loader": "~0.13.0",
"superagent": "~1.6.1",
"superagent-bluebird-promise": "~3.0.0",
"url-loader": "~0.5.7"
}
}
When I deploy I am receiving this error. When I look at bootstrap-loader I don't know what is happening, if someone knows that can point me in the right direction I am most greatful.
Here is similar error https://github.com/shakacode/bootstrap-loader/issues/4
They resolve this by ensuring that latest version of bootstrap-loader is installed:
npm install --save bootstrap-loader#1.0.0-rc
or
npm install --save bootstrap-loader#latest