Webpack-dev-server stops updating after first file change - reactjs

Due to some update, my previously working set up no longer operates as expected. When I run yarn start WDS will look for changes to my files and make the right updates the first time, but any other changes to the file will not be send to the browser, even though WDS acknolodges the file change. Here is my current config
const path = require('path');
const merge = require('webpack-merge');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const WebpackChunkHash = require('webpack-chunk-hash');
require('babel-polyfill');
const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
app: path.join(__dirname, '/Zeus/src'),
build: path.join(__dirname, '/Zeus/dist'),
};
const common = {
entry: {
index: [
'babel-polyfill',
PATHS.app,
],
},
resolve: {
extensions: ['.js', '.jsx', '.scss'],
},
output: {
path: PATHS.build,
publicPath: '/dist/',
filename: '[name].js',
chunkFilename: '[id].[chunkhash].js',
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
include: PATHS.app,
use: {
loader: 'babel-loader',
},
},
{
test: /flickity/,
loader: 'imports-loader?define=>false&this=>window',
}
],
},
plugins: [
new WebpackChunkHash({algorithm: 'md5'}) // 'md5' is default value
],
};
const extractSass = new ExtractTextPlugin({
filename: '[name].css',
disable: process.env.NODE_ENV === 'development',
});
//
// Developmemt configuration
//
if (TARGET === 'start' || !TARGET) {
module.exports = merge(common, {
devtool: 'eval-source-map',
devServer: {
contentBase: path.join(__dirname, '/Zeus'),
historyApiFallback: true,
hot: true,
// hotOnly: true,
clientLogLevel: 'info',
// stats: 'errors-only',
host: '0.0.0.0',
port: 8080,
},
module: {
rules: [{
test: /\.scss$/,
use: extractSass.extract({
use: [{
loader: 'css-loader',
}, {
loader: 'sass-loader',
}],
// use style-loader in development
fallback: 'style-loader',
}),
}],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.ModuleConcatenationPlugin(),
extractSass,
],
});
}
Usually this means I will cancel the process and start it again. Which works, but obviously not very convenient.
[edit]
To include my dir structure, it follows:
/
webpack.config.js
/Zeus
/dist
/src
index.js
I'm using webpack: ^4.29.6.
[edit to include pck file]
{
"name": "zeus",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack --progress",
"start": "webpack-dev-server --debug",
},
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.2.3",
"#babel/core": "^7.3.4",
"#babel/preset-env": "^7.3.4",
"#babel/preset-es2015": "^7.0.0-beta.53",
"#babel/preset-react": "^7.0.0",
"#babel/preset-stage-1": "^7.0.0",
"#babel/preset-stage-3": "^7.0.0",
"#babel/register": "^7.0.0",
"autoprefixer-loader": "^3.2.0",
"axios-mock-adapter": "^1.16.0",
"babel-eslint": "10",
"babel-loader": "^8.0.5",
"babel-polyfill": "^6.26.0",
"chai": "^4.2.0",
"chai-jquery": "^2.1.0",
"css-loader": "^2.1.0",
"enhanced-resolve": "^4.1.0",
"enzyme": "^3.9.0",
"es6-promise-promise": "^1.0.0",
"eslint": "5.x",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.12.4",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"file-loader": "^3.0.1",
"imports-loader": "^0.8.0",
"install": "^0.12.2",
"istanbul": "1.0.0-alpha.2",
"jquery": "^3.3.1",
"jsdom": "^14.0.0",
"mocha": "^6.0.2",
"mock-local-storage": "^1.1.8",
"nock": "^10.0.6",
"node-sass": "^4.11.0",
"offline-plugin": "^5.0.6",
"phantomjs": "^2.1.7",
"plato": "^1.7.0",
"react-addons-test-utils": "^15.6.2",
"redux-mock-store": "^1.5.3",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"tapable": "^1.1.1",
"uglifyjs-webpack-plugin": "^2.1.2",
"url-loader": "^1.1.2",
"watchpack": "^1.6.0",
"webpack": "^4.29.6",
"webpack-chunk-hash": "^0.6.0",
"webpack-cli": "^3.2.3",
"webpack-dev-server": "^3.2.1",
"webpack-merge": "^4.2.1",
"webpack-sources": "^1.3.0"
},
"dependencies": {
"#babel/plugin-proposal-class-properties": "^7.3.4",
"#babel/plugin-syntax-dynamic-import": "^7.2.0",
"#babel/plugin-syntax-import-meta": "^7.2.0",
"#babel/plugin-transform-react-jsx": "^7.3.0",
"#babel/plugin-transform-runtime": "^7.3.4",
"axios": "^0.18.0",
"babel-preset-stage-1": "^6.24.1",
"enzyme-adapter-react-16": "^1.10.0",
"es6-promise": "^4.2.6",
"flickity": "^2.2.0",
"history": "^4.7.2",
"isomorphic-fetch": "^2.2.1",
"jest": "^24.3.1",
"lodash": "^4.17.11",
"moment": "^2.24.0",
"moxios": "^0.4.0",
"npm-check-updates": "^3.1.7",
"prop-types": "^15.7.2",
"query-string": "^6.2.0",
"react": "^16.8.3",
"react-async-script": "^1.0.0",
"react-async-script-loader": "^0.3.0",
"react-autocomplete": "^1.8.1",
"react-dom": "^16.8.3",
"react-ga": "^2.5.7",
"react-google-login": "^5.0.2",
"react-infinite-scroller": "^1.2.4",
"react-loadable": "^5.5.0",
"react-masonry-component": "^6.2.1",
"react-modal": "^3.8.1",
"react-redux": "^7.0.1",
"react-router": "^5.0.0",
"react-router-dom": "^5.0.0",
"react-router-scroll": "^0.4.4",
"react-sticky": "^6.0.3",
"react-waypoint": "^9.0.0",
"redux": "^4.0.1",
"redux-form": "^8.1.0",
"redux-promise": "^0.6.0",
"redux-saga": "^1.0.2",
"redux-storage": "^4.1.2",
"redux-thunk": "^2.3.0"
}
}

Related

my react app is not rendering in internet explorer (because of arrow function)

My react+redux app is not working on Internet explorer 11. It is working fine on edge, Firefox and chrome.
I have already tried so many answers available on internet like this but didn't get any success, below attached error is I am getting in console
when I opened this error it shows like this
this file is generating when I am serving my app and can't change anything manually
package.json
{
"jest": {
"roots": [
"<rootDir>/"
],
"moduleFileExtensions": [
"js",
"jsx",
"json"
],
"testURL": "http://localhost",
"moduleDirectories": [
"node_modules",
"utils"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"coverageReporters": [
"text"
],
"collectCoverageFrom": [
"**/*.{js,jsx}",
"!**/node_modules/**",
"!**/flow-typed/**",
"!**/vendor/**",
"!./*"
],
"setupFilesAfterEnv": [
"./utils/jestUtils/setupTests.js"
],
"testEnvironment": "./utils/jestUtils/freezeDateEnvironment.js",
"moduleNameMapper": {
"\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/utils/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/utils/__mocks__/fileMock.js"
}
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#synapsestudios/react-drop-n-crop": "^0.2.0",
"attr-accept": "^1.1.0",
"axios": "^0.19.0",
"babel-polyfill": "^6.26.0",
"classnames": "^2.2.6",
"clone-deep": "^3.0.1",
"d3": "^4.9.1",
"deep-equal": "^1.0.1",
"draft-js": "0.10.5",
"draft-js-buttons": "2.0.1",
"draft-js-export-html": "1.2.0",
"file-saver": "^1.3.8",
"formsy-react": "^0.19.5",
"history": "^4.6.3",
"libphonenumber-js": "1.7.16",
"locate-path": "^2.0.0",
"mime": "^2.0.3",
"moment": "^2.18.1",
"nanoid": "^1.0.1",
"node": "^12.10.0",
"node-gyp": "^5.0.3",
"path-to-regexp": "^2.2.1",
"prettier": "^1.6.1",
"prop-types": "^15.5.10",
"qs": "6.7.0",
"query-string": "5.1.1",
"react": "16.7.0",
"react-app-polyfill": "^1.0.5",
"react-autofill": "^1.1.4",
"react-cropper": "^1.0.0",
"react-datepicker": "^1.4.1",
"react-dom": "16.7.0",
"react-dropzone": "^4.1.3",
"react-geosuggest": "2.12.0",
"react-html-parser": "^2.0.2",
"react-infinite-scroller": "^1.1.1",
"react-input-range": "^1.1.4",
"react-intl": "^2.4.0",
"react-intl-redux": "^0.7.0",
"react-media": "^1.8.0",
"react-modal": "^2.3.3",
"react-phone-number-input": "2.3.2",
"react-quill": "^1.0.0",
"react-redux": "^5.0.5",
"react-router": "^4.1.1",
"react-router-dom": "^4.1.2",
"react-scripts": "1.0.10",
"react-select": "^1.0.0-rc.5",
"react-select-plus": "^1.1.0",
"react-tooltip": "^3.3.0",
"react-transition-group": "2.5.3",
"recompact": "^3.3.0",
"redux": "4.0.1",
"redux-form": "7.3.0",
"redux-thunk": "^2.2.0",
"reselect": "^3.0.1",
"resolve-url-loader": "^2.0.2",
"select2": "^4.0.3",
"snake-case": "^2.1.0",
"svg-inline-loader": "^0.7.1",
"svg-url-loader": "^2.0.2",
"validator": "^8.0.0"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"ie 11",
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#babel/core": "7.4.4",
"#babel/node": "7.4.5",
"#babel/plugin-proposal-class-properties": "7.4.4",
"#babel/plugin-proposal-object-rest-spread": "7.4.4",
"#babel/plugin-proposal-optional-chaining": "7.2.0",
"#babel/plugin-transform-arrow-functions": "7.2.0",
"#babel/plugin-transform-classes": "7.4.4",
"#babel/plugin-transform-runtime": "7.4.4",
"#babel/preset-env": "7.4.4",
"#babel/preset-flow": "7.0.0",
"#babel/preset-react": "7.0.0",
"autoprefixer": "^9.5.1",
"axios-mock-adapter": "^1.10.0",
"babel-eslint": "10.0.1",
"babel-loader": "8.0.6",
"babel-plugin-react-intl": "3.0.1",
"babel-plugin-react-intl-auto": "1.7.0",
"colors": "1.3.3",
"cross-env": "^5.1.4",
"css-loader": "3.0.0",
"cssnano": "4.1.10",
"del-cli": "^1.1.0",
"enzyme": "3.8.0",
"enzyme-adapter-react-16": "1.7.1",
"eslint": "5.16.0",
"eslint-config-airbnb": "^15.1.0",
"eslint-import-resolver-webpack": "^0.10.1",
"eslint-loader": "^2.1.1",
"eslint-plugin-babel": "^5.1.0",
"eslint-plugin-flowtype": "3.8.2",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jest": "22.1.2",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "^7.1.0",
"file-loader": "3.0.1",
"flow-babel-webpack-plugin": "1.1.1",
"flow-bin": "0.102.0",
"flow-typed": "2.5.2",
"glob": "^7.1.2",
"jest": "24.8.0",
"mini-css-extract-plugin": "^0.6.0",
"node-sass": "^4.12.0",
"postcss-easy-import": "^3.0.0",
"postcss-loader": "^3.0.0",
"react-docgen": "^2.20.1",
"react-hot-loader": "^4.3.12",
"react-test-renderer": "^15.6.2",
"redux-devtools": "3.5.0",
"redux-devtools-dock-monitor": "1.1.3",
"redux-devtools-log-monitor": "1.4.0",
"redux-mock-store": "^1.4.0",
"sass-loader": "^6.0.6",
"uglifyjs-webpack-plugin": "^1.1.2",
"url-loader": "^2.1.0",
"webpack": "4.31.0",
"webpack-cli": "^3.3.2",
"webpack-dev-server": "3.3.1"
}
}
.babelrc
{
"presets": [
["#babel/preset-env", { "targets": { "ie": "11", "esmodules": true }}],
"#babel/preset-react",
"#babel/preset-flow"
],
"plugins": [
"#babel/plugin-transform-runtime",
"#babel/plugin-proposal-object-rest-spread",
"#babel/plugin-proposal-class-properties",
"#babel/plugin-proposal-optional-chaining",
"react-hot-loader/babel",
"#babel/plugin-transform-classes",
"#babel/plugin-transform-arrow-functions"
],
"env": {
"lang":{
"plugins": ["#babel/plugin-syntax-object-rest-spread", ["react-intl", {
"messagesDir": "../assets/build-translations/messages/"
}]]
}
}
}
webpackconfig.js
const { DefinePlugin, NamedModulesPlugin } = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const FlowBabelWebpackPlugin = require('flow-babel-webpack-plugin');
const path = require('path');
require('babel-polyfill');
const webpackAlias = require('./webpack.config.alias');
const pagenames = require('./utils/pageNames');
const DEV_SERVER_PUBLIC_PATH = 'http://192.168.1.14:44444/webpack/static/';
const environment = process.env && process.env.NODE_ENV || 'production';
const PROD = environment === 'production';
const environmentValues = new DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(environment)
});
const UglifyJSPluginInit = new UglifyJSPlugin({
uglifyOptions: {
beautify: false,
ecma: 6,
compress: true,
comments: false,
parallel: true,
sourceMap: true,
warnings: false,
}
});
const flowPlugin = environment === 'lang' ? [] : [new FlowBabelWebpackPlugin()];
const commonPlugins = [environmentValues, ...flowPlugin, new MiniCssExtractPlugin({
filename: '[name].css',
})];
const productionPlugins = [UglifyJSPluginInit];
const pluginsArr = PROD
? [...commonPlugins, ...productionPlugins]
: [...commonPlugins, new NamedModulesPlugin()];
const devtool = PROD ? false : 'cheap-source-map';
const imagePublicPath = PROD ? '/static/' : DEV_SERVER_PUBLIC_PATH;
const modeAlias = PROD ? 'production' : 'development';
const outputPath = path.resolve(__dirname, '../assets');
const entry = {
app: './utils/app.js',
'password-reset': './utils/scss/password-reset.scss',
[pagenames.pageNames1]: './fileurl.js',
[pagenames.pageNames2]: './fileurl.js',
[pagenames.pageNames3]: './fileurl.js',
[pagenames.pageNames4]: './fileurl.js',
};
const config = {
...webpackAlias,
mode: modeAlias,
optimization: {
splitChunks: {
cacheGroups: {
commons: {
minChunks: 13,
name: 'commons',
chunks: 'all',
},
},
}
},
context: __dirname,
entry,
devtool,
output: {
path: outputPath,
publicPath: '/webpack/static/',
filename: '[name].js',
},
devServer: {
contentBase: outputPath,
port: 44444,
host: '192.168.1.14',
publicPath: DEV_SERVER_PUBLIC_PATH,
stats: {
errors: true,
warnings: true,
assets: false,
chunks: true,
chunkGroups: true,
chunkModules: true,
chunkOrigins: true,
builtAt: false,
cached: false,
timings: false,
outputPath: false,
modules: true,
entrypoints: true,
},
headers: {
"Access-Control-Allow-Origin": "\*",
}
},
module: {
rules: [
{
test: /\.svg$/,
loader: 'svg-url-loader'
},
{
test: /\.js$/,
exclude: path.resolve(__dirname, "node_modules"),
include: __dirname,
use: [
{
loader: 'babel-loader',
},
{
loader: 'eslint-loader',
options: {
failOnWarning: false,
failOnError: true
}
}
]
},
{
test: /\.(png|jpg)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000, // Convert images < 10kb to base64 strings
publicPath: imagePublicPath // Since the fallback is file-loader, We end up serving from /static/{file} or during development - wherever the server is located
}
}
]
},
{
test: /\.scss|css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: !PROD,
reloadAll: true,
},
},
{
loader: 'css-loader',
options: {
sourceMap: true,
}
},
{ loader: 'postcss-loader' },
{
loader: 'resolve-url-loader'
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
},
]
}
]
},
plugins: pluginsArr
};
console.log('process.env.NODE_ENV', environment);
module.exports = config;
Any help would be appreciated, Thanks in advance.
I can see on your .babelrc presets, under #babel/preset-env you are defining "esmodules": true.
Based on the #babel/preset-env documentation, if you set esmodules to true, browsers targets will be ignored.
Please note: when specifying the esmodules target, browsers targets will be ignored.
Can you try changing this option to see if you have any luck?
Also, I suggest you try a production build to see if you get the same error/behavior.
Try to delete the package-lock.json and the node_modules folder, then using the following package.json content (change the name to your application name. In this file, I changed some package version.) and execute the npm install commands to install the related package. I have created a sample using this file, it works well on my side.
{
"name": "<your application name>",
"version": "0.1.0",
"private": true,
"dependencies": {
"#synapsestudios/react-drop-n-crop": "^0.2.0",
"attr-accept": "^1.1.0",
"axios": "^0.19.0",
"babel-polyfill": "^6.26.0",
"classnames": "^2.2.6",
"clone-deep": "^3.0.1",
"d3": "^4.9.1",
"deep-equal": "^1.0.1",
"draft-js": "0.10.5",
"draft-js-buttons": "2.0.1",
"draft-js-export-html": "1.2.0",
"file-saver": "^1.3.8",
"formsy-react": "^0.19.5",
"history": "^4.6.3",
"libphonenumber-js": "1.7.16",
"locate-path": "^2.0.0",
"mime": "^2.0.3",
"moment": "^2.18.1",
"nanoid": "^1.0.1",
"node": "^12.10.0",
"node-gyp": "^5.0.3",
"path-to-regexp": "^2.2.1",
"prettier": "^1.6.1",
"prop-types": "^15.5.10",
"qs": "6.7.0",
"query-string": "5.1.1",
"raf": "^3.4.1",
"react": "^16.8.6",
"react-app-polyfill": "^1.0.1",
"react-autofill": "^1.1.4",
"react-cropper": "^1.0.0",
"react-datepicker": "^1.4.1",
"react-dom": "^16.8.6",
"react-dropzone": "^4.1.3",
"react-geosuggest": "2.12.0",
"react-html-parser": "^2.0.2",
"react-infinite-scroller": "^1.1.1",
"react-input-range": "^1.3.0",
"react-intl": "^2.4.0",
"react-intl-redux": "^0.7.0",
"react-media": "^1.8.0",
"react-modal": "^2.3.3",
"react-phone-number-input": "2.3.2",
"react-quill": "^1.0.0",
"react-redux": "^7.1.0",
"react-router": "^4.1.1",
"react-router-dom": "^4.1.2",
"react-scripts": "3.0.1",
"react-select": "^1.0.0-rc.5",
"react-select-plus": "^1.1.0",
"react-tooltip": "^3.3.0",
"react-transition-group": "2.5.3",
"recompact": "^3.3.0",
"redux": "^4.0.4",
"redux-form": "^8.2.5",
"redux-thunk": "^2.2.0",
"reselect": "^3.0.1",
"resolve-url-loader": "^2.0.2",
"select2": "^4.0.3",
"snake-case": "^2.1.0",
"svg-inline-loader": "^0.7.1",
"svg-url-loader": "^2.0.2",
"validator": "^8.0.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"ie 11",
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#babel/core": "7.4.4",
"#babel/node": "7.4.5",
"#babel/plugin-proposal-class-properties": "7.4.4",
"#babel/plugin-proposal-object-rest-spread": "7.4.4",
"#babel/plugin-proposal-optional-chaining": "7.2.0",
"#babel/plugin-transform-arrow-functions": "7.2.0",
"#babel/plugin-transform-classes": "7.4.4",
"#babel/plugin-transform-runtime": "7.4.4",
"#babel/preset-env": "7.4.4",
"#babel/preset-flow": "7.0.0",
"#babel/preset-react": "7.0.0",
"autoprefixer": "^9.5.1",
"axios-mock-adapter": "^1.10.0",
"babel-eslint": "10.0.1",
"babel-loader": "8.0.6",
"babel-plugin-react-intl": "3.0.1",
"babel-plugin-react-intl-auto": "1.7.0",
"colors": "1.3.3",
"cross-env": "^5.1.4",
"css-loader": "3.0.0",
"cssnano": "4.1.10",
"del-cli": "^1.1.0",
"enzyme": "3.8.0",
"enzyme-adapter-react-16": "1.7.1",
"eslint": "5.16.0",
"eslint-config-airbnb": "^15.1.0",
"eslint-import-resolver-webpack": "^0.10.1",
"eslint-loader": "^2.1.1",
"eslint-plugin-babel": "^5.1.0",
"eslint-plugin-flowtype": "3.8.2",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jest": "22.1.2",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "^7.1.0",
"file-loader": "3.0.1",
"flow-babel-webpack-plugin": "1.1.1",
"flow-bin": "0.102.0",
"flow-typed": "2.5.2",
"glob": "^7.1.2",
"jest": "24.8.0",
"mini-css-extract-plugin": "^0.6.0",
"node-sass": "^4.12.0",
"postcss-easy-import": "^3.0.0",
"postcss-loader": "^3.0.0",
"react-docgen": "^2.20.1",
"react-hot-loader": "^4.3.12",
"react-test-renderer": "^15.6.2",
"redux-devtools": "^3.5.0",
"redux-devtools-dock-monitor": "1.1.3",
"redux-devtools-log-monitor": "1.4.0",
"redux-mock-store": "^1.4.0",
"sass-loader": "^6.0.6",
"uglifyjs-webpack-plugin": "^1.1.2",
"url-loader": "^2.1.0",
"webpack": "4.31.0",
"webpack-cli": "^3.3.2",
"webpack-dev-server": "3.3.1"
}
}
Unless you're supplying a .babelrc or babel.config.js (documentation) that you didn't include with your question, then your #babel/preset-env dependency may not be getting applied during transpilation.
The default behavior for #babel/preset-env is to transpile down to EMCAScript 2015+, which would then work for IE11.
Sidenote, if no targets are specified, #babel/preset-env will transform all ECMAScript 2015+ code by default.
I would suggest adding one of those. For example:
.babelrc
{
"presets": ["#babel/preset-env"]
}
babel.config.js
module.exports = function (api) {
api.cache(true);
return {
presets: ["#babel/preset-env"],
};
}
If the arrow function is ending up in the browser, then it doesn’t look like you are transpiling your code before serving it to the browser. I see your installing webpack and Babel, but their are no scripts in your package.json to run either. As you have not shared a webpack config, you give us little to go on without seeing how the rest of your project is setup
I would suggest moving your code into create-react-app and try running it from that.
Till now Internet Explorer 11 does not ECMAScript 6 (ES6) version of JavaScript.You have to write the function in old ways (curly brackets).Some thing like below:
var name = ""
function func1(filter){
if (filter instanceof RegExp === true)
return filter.text(name)
else{
return filter === name
}
}
function testParameter(name, filters){
name = this.name
return filters.some(func1);
}
Array.some() function is of ES5 which is supported in Internet Explorer.
Reference:
https://interoperability.blob.core.windows.net/web/MS-ES5EX/%5BMS-ES5EX%5D-180828.pdf

npm start displays generated js file in browser

I'm getting generated js file in browser when I'm doing npm start.
I'm using
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0",
"webpack-dev-server": "^3.2.1",
"webpack-manifest-plugin": "^2.0.4"
Below is my webpack.config.js.
Please tell me what I'm doing wrong here
I'm getting generated js file on browser when I do npm start.
I'm using
"webpack": "^4.29.6"
"webpack-cli": "^3.3.0"
"webpack-dev-server": "^3.2.1"
Below is my webpack.config.js
Please tell me what I'm doing wrong here.
const cssFilename = 'static/css/style.[hash].css';
module.exports = {
entry: './src/index.js',
externals: [nodeExternals()],
mode: "production",
resolve: {
extensions: ['.js', '.json', '.jsx', '.css', '.svg']
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
include: path.resolve(__dirname, 'src'),
use: {
loader: 'babel-loader',
options: {
presets: ['#babel/env', '#babel/react']
}
}
},
{
test: /\.css?$/,
include: path.resolve(__dirname, 'src'),
exclude: /(node_modules|bower_components)/,
use: ['raw-loader','style-loader','to-string-loader','css-loader']
}
]
},
devtool: 'inline-source-map',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'static/js/bundle.[hash].js',
chunkFilename: 'static/js/bundle.[hash].js',
publicPath: './'
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new HtmlWebpackPlugin({
filename: './index.html',
template: './public/index.html'
})
]
};
Package.json
{
"name": "demo",
"version": "1.0.0",
"description": "demo",
"private": true,
"jest": {
"collectCoverageFrom": [
"src/Actions/"
],
"coverageThreshold": {
"global": {
"branches": 10,
"functions": 10,
"lines": 10,
"statements": 10
}
}
},
"scripts": {
"watch": "webpack --watch",
"start": "webpack-dev-server",
"build": "webpack",
"test": "set CI=true &&jest --coverage"
},
"homepage": ".",
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.2.3",
"#babel/core": "^7.2.3",
"#babel/plugin-proposal-class-properties": "^7.3.0",
"#babel/plugin-syntax-dynamic-import": "^7.2.0",
"#babel/preset-env": "^7.2.3",
"#babel/preset-flow": "^7.0.0",
"#babel/preset-react": "^7.0.0",
"babel-eslint": "9.0.0",
"babel-loader": "^8.0.5",
"babel-register": "^6.26.0",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"jest": "^24.5.0",
"jest-environment-enzyme": "^7.0.1",
"jest-enzyme": "^7.0.1",
"mini-css-extract-plugin": "^0.5.0",
"raw-loader": "^0.5.1",
"react-svg-loader": "^2.1.0",
"source-map-loader": "^0.2.4",
"to-string-loader": "^1.1.5",
"ts-jest": "^23.10.1",
"typescript": "^3.0.3",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0",
"webpack-dev-server": "^3.2.1",
"webpack-manifest-plugin": "^2.0.4"
},
"exclude": [
"node_modules"
],
"dependencies": {
"axios": "^0.18.0",
"axios-mock-adapter": "^1.16.0",
"babel-preset-react-app": "^7.0.2",
"css-loader": "^2.1.1",
"file-loader": "^3.0.1",
"file-saver": "^1.3.8",
"lodash": "^4.17.10",
"postcss-flexbugs-fixes": "^4.1.0",
"postcss-loader": "^3.0.0",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-redux": "^5.1.1",
"redux": "^4.0.0",
"redux-thunk": "^2.3.0",
"style-loader": "^0.23.1",
"url-loader": "^1.1.2",
"webpack-node-externals": "^1.7.2"
}
}

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory?

JavaScript head out of memory while I compile using webpack build system. I don't know what is the problem.
Snapshot of error while on npm run build:prod
I'm using:
OS: Ubuntu 16.04,
RAM: 8Gig,
Processor: Inter Core-i5
Node.js, babel-minify-webpack-plugin.
Reactjs 16.2,and Redux
Here is Webpack.config.js file:
var webpack = require('webpack');
var path = require('path');
const env = process.env.NODE_ENV || 'development'
const MinifyPlugin = require("babel-minify-webpack-plugin");
module.exports = {
entry: {
'/js/app': './frontend/app.js'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'public')
},
module: {
rules: [
{
test: /\.(scss|css|sass)$/i,
use: [{
loader: "style-loader"
}, {
loader: "css-loader"
}, {
loader: "sass-loader",
options: {
includePaths: [
path.resolve("./node_modules/")
]
}
}]
},
{
test: /\.js$/,
loader: 'babel-loader',
include: path.join(__dirname, "frontend"),
exclude: path.resolve(__dirname, "node_modules"),
query: {
presets: ['es2015', 'react']
}
},
{
test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
loader: 'url-loader?limit=4096&name=[name]-[hash].[ext]'
},
{
test: /\.json$/,
loader: 'json-loader'
}
]
},
externals: {
jquery: 'jQuery'
},
node: {
fs: "empty",
net: "empty"
},
plugins: [
new webpack.ProvidePlugin({
'videojs': 'video.js',
'window.videojs': 'video.js'
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new MinifyPlugin(true, true)
]
};
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
Here is my package.json file:
{
"name": "node-ejs",
"version": "1.0.0",
"description": "this is our first app using nodejs on express server with babel",
"main": "server.js",
"proxy": "http://10.1.0.7",
"scripts": {
"start": "nodemon ./server.js --exec babel-node --presets env",
"build:debug": "webpack -d --progress --colors",
"build:prod": "webpack -p --progress --colors",
"build": "webpack --config webpack.config.js"
},
"keywords": [
"nodejs",
"babel",
"express"
],
"watch": true,
"author": "",
"license": "ISC",
"dependencies": {
"#blueprintjs/core": "^1.35.0",
"axios": "^0.17.1",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-minify-builtins": "^0.4.0",
"babel-plugin-minify-flip-comparisons": "^0.4.0",
"babel-preset-es2015": "^6.24.1",
"body-parser": "^1.18.2",
"bootstrap": "^3.3.7",
"ejs": "^2.5.7",
"express": "^4.16.2",
"express-ejs-extend": "0.0.1",
"firebase": "^4.8.2",
"js-file-download": "^0.4.1",
"json-loader": "^0.5.7",
"material-design-icons": "^3.0.1",
"moment": "^2.22.0",
"node-sass": "^4.7.2",
"nodemon": "^1.14.5",
"npm": "^5.8.0",
"npm-install-peers": "^1.2.1",
"pure-render-decorator": "^1.2.1",
"query-string": "^6.0.0",
"re-base": "^3.2.2",
"react-addons-css-transition-group": "^15.6.2",
"react-bootstrap": "^0.31.5",
"react-breadcrumbs-dynamic": "^1.0.12",
"react-dom": "^16.2.0",
"react-file-download": "^0.3.5",
"react-jplayer": "^7.1.2",
"react-notifications": "^1.4.3",
"react-owl-carousel2": "^0.2.1",
"react-pager": "^1.3.3",
"react-placeholder": "^2.0.0",
"react-redux": "^5.0.6",
"react-rev-slider": "^1.0.1",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"react-router-redux": "^4.0.8",
"react-share": "^1.19.0",
"react-slick": "^0.20.0",
"redux": "^3.7.2",
"redux-promise-middleware": "^5.0.0",
"redux-thunk": "^2.2.0",
"sass-loader": "^6.0.6",
"save-dev": "^2.0.0",
"scss-loader": "0.0.1",
"slick-carousel": "^1.8.1",
"update": "^0.7.4",
"video.js": "^6.6.0",
"videojs-contrib-dash": "^2.9.2",
"videojs-ima": "^1.0.1",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.9.7"
},
"devDependencies": {
"#babel/preset-env": "^7.0.0-beta.44",
"babel-cli": "^6.26.0",
"babel-minify": "^0.4.0",
"babel-minify-webpack-plugin": "^0.3.1",
"babel-preset-env": "^1.6.1",
"babel-preset-minify": "^0.4.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-1": "^6.24.1",
"babel-register": "^6.26.0",
"css-loader": "^0.28.7",
"file-loader": "^1.1.6",
"img-loader": "^2.0.0",
"jquery": "^3.2.1",
"lodash": "^4.17.4",
"postcss-loader": "^2.0.10",
"react": "^16.2.0",
"react-dfp": "^0.7.0",
"react-modal": "^3.1.10",
"react-router-bootstrap": "^0.24.4",
"style-loader": "^0.19.1",
"url-loader": "^0.6.2"
}
}
I can pass this error by this code
$ NODE_OPTIONS="--max-old-space-size=1024" yarn test

ERROR in ./node_modules/babel-core/lib/helpers/resolve.js When trying to build from webpack

I am getting this error when I install babel-core in dependencies, If I Install babel-core in Devdependencies it works, but I need babel-core in dependencies, How to surpass this issue? Is there a way in which I can install Babel-core in Dependencies and not get this error?
ERROR in ./node_modules/babel-core/lib/helpers/resolve.js
Module not found: Error: Can't resolve 'module' in '/app/node_modules/babel-core/lib/helpers'
# ./node_modules/babel-core/lib/helpers/resolve.js 34:14-31
# ./node_modules/babel-core/lib/transformation/file/options/build-
configchain.js
This is my webpack config.dll file,
How to go by this issue?
const os = require('os');
const path = require('path');
const webpack = require('webpack');
const HappyPack = require('happypack');
const paths = require('./paths');
const vendors = Object.keys(require(path.join(__dirname, '../package')).dependencies); // eslint-disable-line
let outputPath = path.join(__dirname, '..', 'dev', 'static', 'js');
if (process.env.NODE_ENV === 'production') {
outputPath = path.join(__dirname, '..', 'build', 'static', 'js');
}
const config = {
node: {
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
},
entry: {
vendor: vendors,
},
output: {
path: outputPath,
filename: '[name].dll.js',
library: '[name]_[hash]',
publicPath: '/static/js/',
},
plugins: [
new HappyPack({
loaders: ['babel-loader'],
threads: process.env.BUILD_CPUS ? parseInt(process.env.BUILD_CPUS) : ((os.cpus().length - 1) || 1),
}),
new webpack.DllPlugin({
path: path.join(__dirname, '..', 'config', '[name]-manifest.json'),
name: '[name]_[hash]',
context: path.resolve(__dirname),
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}),
],
module: {
rules: [
{
test: /\.js$/,
include: path.join(__dirname, '../node_modules/nested-set'),
loader: 'happypack/loader',
},
],
},
resolve: {
modules: ['node_modules'],
extensions: ['.js', '.json'],
alias: {
react: path.join(paths.appNodeModules, '/react'),
'react-dom': path.join(paths.appNodeModules, '/react-dom'),
},
},
};
if (process.env.NODE_ENV === 'production') {
config.plugins.push(new webpack.optimize.UglifyJsPlugin());
}
module.exports = config;
And these are my dependencies,
"devDependencies": {
"add-asset-html-webpack-plugin": "^2.0.1",
"amdefine": "^1.0.1",
"autoprefixer": "6.7.*",
"babel-eslint": "^7.2.3",
"babel-jest": "^20.0.3",
"babel-loader": "^7.1.1",
"babel-plugin-dynamic-import-webpack": "^1.0.1",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-react-app": "2.2.*",
"babel-preset-stage-0": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"babel-runtime": "^6.23.0",
"case-sensitive-paths-webpack-plugin": "^2.1.1",
"chalk": "1.1.*",
"connect-history-api-fallback": "1.3.*",
"cpr": "^2.2.0",
"cross-spawn": "4.0.*",
"css-loader": "0.26.*",
"detect-port": "1.1.*",
"dotenv": "^4.0.0",
"eslint": "3.19.*",
"eslint-config-airbnb": "14.1.*",
"eslint-config-react-app": "0.6.*",
"eslint-loader": "1.6.*",
"eslint-plugin-flowtype": "2.21.*",
"eslint-plugin-import": "2.2.*",
"eslint-plugin-jsx-a11y": "4.0.*",
"eslint-plugin-react": "6.10.*",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "0.10.*",
"fs-extra": "0.30.*",
"happypack": "^4.0.0-beta.1",
"has-flag": "^2.0.0",
"html-webpack-plugin": "^2.29.0",
"http-proxy-middleware": "0.17.*",
"jest": "^20.0.4",
"json-loader": "0.5.*",
"locate-path": "^2.0.0",
"object-assign": "4.1.*",
"postcss-loader": "1.2.*",
"preload-webpack-plugin": "^1.2.2",
"promise": "7.1.*",
"react-dev-utils": "^3.0.2",
"react-error-overlay": "^1.0.9",
"style-loader": "0.13.*",
"url-loader": "0.5.*",
"webpack": "^3.1.0",
"webpack-dev-server": "^2.5.1",
"whatwg-fetch": "2.0.2"
},
"dependencies": {
"ajv": "4.10.0",
"babel-core": "^6.26.0",
"babel-polyfill": "^6.26.0",
"copy-to-clipboard": "3.0.*",
"core-js": "^2.5.1",
"downloadjs": "1.4.*",
"es-abstract": "^1.7.0",
"function-bind": "^1.1.0",
"has": "^1.0.1",
"html2canvas": "^0.5.0-beta4",
"jspdf": "^1.3.5",
"marked": "0.3.3",
"marksy": "5.0.*",
"material-ui": "0.18.*",
"moment": "2.18.1",
"nested-set": "^1.0.0-rc0",
"object.entries": "^1.0.4",
"pdfjs-dist": "^1.9.528",
"prop-types": "15.5.1*",
"react": "15.4.*",
"react-cellblock": "3.0.*",
"react-chatview": "0.2.*",
"react-code-splitting": "^1.1.1",
"react-datepicker": "0.52.0",
"react-dom": "15.4.*",
"react-infinite": "^0.12.1",
"react-intl": "2.3.*",
"react-joyride": "1.11.*",
"react-pdf": "^2.0.0",
"react-redux": "5.0.*",
"react-router": "4.0.*",
"react-router-dom": "4.0.*",
"react-sortable-tree": "^1.5.3",
"react-tap-event-plugin": "2.0.*",
"react-virtualized": "^9.9.0",
"react-visibility-sensor": "^3.10.1",
"redux": "3.6.*",
"striptags": "2.2.1",
"url-parse": "^1.1.9",
"uuid": "^3.1.0"
},

Trying to bundle first React app - bundle is too big

I have first react app - which is 5.5Mb when using developer mode and devtool: "source-map". Now I tried to write webpack for distribution mode like this:
var webpack = require('webpack');
var path = require('path');
var fs = require('fs')
var BUILD_DIR = path.resolve(__dirname, 'public/javascripts');
var APP_DIR = path.resolve(__dirname, 'frontend');
const babelSettings = JSON.parse(fs.readFileSync(".babelrc"))
var config = {
entry: APP_DIR + '/app.jsx',
output: {
path: BUILD_DIR,
filename: 'bundle.js',
},
module : {
loaders : [
{
test : /\.jsx?/,
include : APP_DIR,
use : ['babel-loader']
}
,
{
test: /\.css$/,
use: ["style-loader",{
loader: "css-loader",
options: {
minimize: true
}
}],
},
{
test: /\.less$/,
use: ["style-loader,less-loader"]
},
{
test: /\.svg$/,
loaders: [
{
loader: 'babel-loader',
query: {
presets: ['es2015']
}
},
{
loader: 'react-svg-loader',
query: {
jsx: true
}
}
],
exclude: /node_modules/
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true
}
})
]
};
babelSettings.plugins.push("transform-react-inline-elements");
babelSettings.plugins.push("transform-react-constant-elements");
module.exports = config;
I run it with :
webpack --config webpack-dist.config.js -p --progress --production --optimize-minimize
The output is still 2.2Mb which is unacceptable size.What config did I miss?
Edit packages.json looks like this:
{
"name": "project",
"version": "0.1.0",
"private": true,
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.22.0",
"babel-preset-stage-3": "^6.22.0",
"babelify": "^7.3.0",
"browserify": "^13.3.0",
"css-loader": "^0.28.0",
"exorcist": "^0.4.0",
"gulp-livereload": "^3.8.1",
"gulp-sourcemaps": "^2.4.0",
"less": "^2.7.2",
"less-loader": "^2.2.3",
"react-edit-inline": "^1.0.8",
"react-image-fallback": "^4.0.1",
"react-scripts": "0.8.5",
"redux-devtools-extension": "^2.13.0",
"remote-redux-devtools": "^0.5.0",
"riek": "^1.0.7",
"style-loader": "^0.13.1",
"svg-react-loader": "^0.4.0-beta.2",
"vinyl-buffer": "^1.0.0",
"watchify": "^3.8.0",
"webpack": "^2.3.2"
},
"dependencies": {
"axios": "^0.16.0",
"barcoder": "^2.0.1",
"escape-string-regexp": "^1.0.5",
"frisbee": "^1.1.7",
"i18next": "^5.0.0",
"i18next-browser-languagedetector": "^1.0.1",
"i18next-xhr-backend": "^1.3.0",
"immutability-helper": "^2.1.1",
"lodash": "^4.17.4",
"qrcode.react": "^0.6.1",
"rc-time-picker": "^2.3.3",
"react": "^15.4.2",
"react-autosuggest": "^8.0.0",
"react-bootstrap": "^0.30.7",
"react-cards": "^0.2.2",
"react-collapse": "^2.3.3",
"react-cookie": "^1.0.4",
"react-dom": "^15.4.2",
"react-dropzone": "^3.10.0",
"react-height": "^2.2.0",
"react-highlight-words": "^0.6.0",
"react-i18next": "^2.0.0",
"react-infinite-scroller": "^1.0.4",
"react-input-autosize": "^1.1.0",
"react-isolated-scroll": "^0.1.0",
"react-loaders": "^2.3.0",
"react-motion": "^0.4.7",
"react-number-input": "^15.0.0-rc2",
"react-numeric-input": "^2.0.7",
"react-popover": "^0.4.4",
"react-preload": "^0.5.0",
"react-redux": "^5.0.2",
"react-redux-form": "^1.5.4",
"react-router-dom": "^4.0.0",
"react-select": "^1.0.0-rc.3",
"react-svg-loader": "^1.1.1",
"react-switch-button": "^2.1.1",
"react-tabs": "^0.8.2",
"react-tagsinput": "^3.14.0",
"redux": "^3.6.0",
"redux-thunk": "^2.2.0",
"simple-react-pdf": "^1.0.6",
"style-it": "^1.5.5",
"throttle-debounce": "^1.0.1",
"validator": "^6.2.1"
},
Use the excellent Webpack Bundle Analyzer to look at what is taking up space in your build.
Also, try setting NODE_ENV=production before you run webpack, it makes a difference.
What decreased bundle size for me (with Webpack 4) is adding
module.exports = {
mode: 'production', // ← this
...
}
(inside webpack.config.js). From almost 1 MB to 158 kB.

Resources