Babel failes to compile plugin it should be ignoring - reactjs

Trying to compile my code with the webpack loader which i have set to ignore node_modules and have not been able to bypass the error below. I've tried clearing out my node_modules and reinstalling as well as adding and removing packages but have been unable to clear the block:
/home/mgarf/Documents/testApp/node_modules/babel-plugin- transform-react-jsx/lib/index.js:16
var visitor = require("babel-helper-builder-react-jsx")({ /*istanbul ignore next*/
^
TypeError: require(...) is not a function
at exports.default (index.js:14:17)
at Function.memoisePluginContainer (/home/mgarf/Documents/testApp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:134:13)
at Function.normalisePlugin (/home/mgarf/Documents/testApp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:168:32)
at /home/mgarf/Documents/testApp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:208:30
at Array.map (native)
at Function.normalisePlugins (/home/mgarf/Documents/testApp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:180:20)
at OptionManager.mergeOptions (/home/mgarf/Documents/testApp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:300:36)
at /home/mgarf/Documents/testApp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:371:14
at /home/mgarf/Documents/testApp/node_modules/babel-core/lib/transformation/file/options/option-manager.js:392:24
at Array.map (native)
Here is my webpackconfig snippet.
var webpack = require('webpack');
require('style-loader');
require('css-loader');
require('babel-register')({
ignore: /\.css$/,
});
...
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
plugins: [
['react-transform', {
transforms: [
{
transform: 'react-transform-hmr',
imports: ['react'],
locals: ['module']
}, {
transform: 'react-transform-catch-errors',
imports: ['react', 'redbox-react']
}
]
}]
]
}
},
{ test: /\.css$/, exclude: /node_modules/, loader: "style-loader!css-loader" }
]
}
and package.json:
"dependencies": {
"async": "^1.5.2",
"bcrypt-nodejs": "^0.0.3",
"body-parser": "^1.15.1",
"bookshelf": "^0.10.0",
"compression": "^1.6.2",
"cookie-parser": "^1.4.1",
"dotenv": "^2.0.0",
"express": "^4.13.4",
"express-validator": "^2.20.4",
"jsonwebtoken": "^5.7.0",
"knex": "^0.11.7",
"moment": "^2.12.0",
"morgan": "^1.7.0",
"mysql": "^2.10.2",
"nodemailer": "^2.3.0",
"nunjucks": "^2.4.1",
"react": "^15.2.1",
"react-cookie": "^0.4.5",
"react-dom": "^15.2.1",
"react-redux": "^4.4.5",
"react-router": "^2.4.0",
"react-transform-catch-errors": "^1.0.2",
"react-transform-hmr": "^1.0.4",
"redbox-react": "^1.2.4",
"redux": "^3.3.1",
"redux-thunk": "^2.0.1",
"request": "^2.69.0",
"webpack": "^1.12.14",
"webpack-dev-middleware": "^1.6.1",
"webpack-hot-middleware": "^2.10.0",
"whatwg-fetch": "^0.11.0"
},
"devDependencies": {
"babel-core": "^6.7.2",
"babel-loader": "^6.2.4",
"babel-plugin-react-transform": "^2.0.2",
"babel-polyfill": "^6.7.2",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-plugin-react-transform": "^2.0.0-beta1",
"babel-plugin-rewire": "^1.0.0-rc-3",
"babel-plugin-transform-export-extensions": "^6.8.0",
"babel-register": "^6.8.0",
"chai": "^3.5.0",
"css-loader": "^0.23.1",
"enzyme": "^2.3.0",
"fetch-mock": "3.0.2",
"mocha": "^2.4.5",
"react-addons-test-utils": "^15.0.2",
"react-date-picker": "^5.3.21",
"redux-mock-store": "^1.0.2",
"sinon": "^1.17.3",
"sinon-chai": "^2.8.0",
"style-loader": "^0.13.1",
"supertest": "^1.2.0"
},
"engines": {
"node": "6.1.0"
}
}

Related

babel 7 how to connect polyfill correctly?

How to connect polyfill correctly?
I read all the documentation Babel 7 and followed it. Below you can see my settings.
if I add this in the webpack config
entry: [
'core-js/stable',
'regenerator-runtime/runtime',
'./main.js'
],
then everything works. but according to the documentation this line can be removed, since all the settings in the babel.config.js
If i remove from entry this line, redux store not working in IE11
babel.config.js
module.exports = function (api) {
api.cache(true);
return {
presets: [
[
'#babel/preset-env',
{
debug: true,
useBuiltIns: 'entry',
corejs: {
version: '3.6',
proposals: false
},
}
],
'#babel/preset-react',
'rsuite'
],
plugins: [
'react-hot-loader/babel',
'#babel/plugin-proposal-class-properties',
'#babel/plugin-proposal-export-default-from',
'#babel/plugin-proposal-object-rest-spread',
'#babel/plugin-syntax-object-rest-spread',
'#babel/plugin-transform-arrow-functions',
'#babel/plugin-transform-async-to-generator',
'#babel/plugin-transform-classes',
'#babel/plugin-transform-parameters',
'#babel/plugin-transform-property-literals',
['#babel/plugin-transform-runtime',
{
corejs: {
version: 3,
proposals: true
}
}
],
'#babel/plugin-transform-spread',
'#babel/plugin-transform-template-literals',
'babel-plugin-styled-components',
]
};
};
package.json
"devDependencies": {
"#babel/core": "^7.9.0",
"#babel/plugin-proposal-class-properties": "^7.8.3",
"#babel/plugin-proposal-export-default-from": "^7.8.3",
"#babel/plugin-proposal-export-namespace-from": "^7.8.3",
"#babel/plugin-proposal-object-rest-spread": "^7.9.5",
"#babel/plugin-syntax-object-rest-spread": "^7.8.3",
"#babel/plugin-transform-arrow-functions": "^7.8.3",
"#babel/plugin-transform-async-to-generator": "^7.8.3",
"#babel/plugin-transform-classes": "^7.9.5",
"#babel/plugin-transform-parameters": "^7.9.5",
"#babel/plugin-transform-property-literals": "^7.8.3",
"#babel/plugin-transform-runtime": "^7.9.0",
"#babel/plugin-transform-spread": "^7.8.3",
"#babel/plugin-transform-template-literals": "^7.8.3",
"#babel/preset-env": "^7.9.5",
"#babel/preset-react": "^7.9.4",
"#devexpress/dx-react-grid-material-ui": "^2.4.0",
"babel-eslint": "^7.2.3",
"babel-helper-annotate-as-pure": "^7.0.0-beta.3",
"babel-jest": "^23.6.0",
"babel-loader": "^8.0.2",
"babel-plugin-styled-components": "^1.10.7",
"babel-preset-rsuite": "^4.0.1",
"clean-webpack-plugin": "^3.0.0",
"colors": "^1.3.2",
"copy-webpack-plugin": "^4.5.2",
"cross-env": "^5.2.0",
"css-loader": "^3.2.0",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-loader": "^2.1.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.11.1",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"file-loader": "^2.0.0",
"html-webpack-plugin": "^3.2.0",
"image-webpack-loader": "^6.0.0",
"less": "^3.8.1",
"less-loader": "^4.1.0",
"mini-css-extract-plugin": "^0.7.0",
"optimize-css-assets-webpack-plugin": "^3.2.1",
"react-highlight-words": "^0.10.0",
"react-hot-loader": "^4.7.2",
"redux-saga": "^0.16.2",
"style-loader": "^0.23.1",
"terser-webpack-plugin": "^1.2.3",
"webpack": "^4.42.1",
"webpack-bundle-analyzer": "^3.6.1",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.8"
},
"dependencies": {
"#babel/runtime": "^7.9.2",
"#babel/runtime-corejs3": "^7.9.2",
"#hot-loader/react-dom": "^16.13.0",
"axios": "^0.19.2",
"c3": "0.4.11",
"cookie": "^0.3.1",
"core-js": "^3.6.5",
"date-fns": "^2.0.0",
"file-saver": "^2.0.2",
"jquery": "^3.4.1",
"js-base64": "^2.5.2",
"lodash": "^4.17.11",
"moment": "^2.24.0",
"normalizr": "^3.3.0",
"prop-types": "^15.7.2",
"query-string": "^5.1.1",
"ramda": "^0.26.1",
"rc-tree": "^3.1.1",
"react": "^16.8.3",
"react-datepicker": "^2.8.0",
"react-dom": "^16.8.3",
"react-html-parser": "^2.0.2",
"react-paginate": "^6.3.0",
"react-redux": "^7.1.0-rc.1",
"react-router-dom": "^4.4.0-beta.7",
"react-scrollbar": "^0.5.6",
"react-select": "^2.4.1",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"redux-thunk": "^2.3.0",
"regenerator-runtime": "^0.13.5",
"reselect": "^3.0.1",
"rsuite": "^4.1.4",
"styled-components": "^4.1.3"
}
webpack rules
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.css$/,
use: cssLoaders()
},
{
test: /\.less$/,
exclude: /node_modules/,
use: cssLoaders('less-loader')
},
{
test: /\.(png|jpg|svg|gif?)$/,
use: 'file-loader'
},
{
test: /\.(woff|woff2|eot|ttf|otf?)$/,
use: 'file-loader'
},
]
},
Just don't remove these lines you've added for the polyfills
entry: [
'core-js/stable',
'regenerator-runtime/runtime',
'./main.js'
],
You are doing right, give us the link to the documentation where it is said this line can be removed. I think it's a misunderstanding.
Or maybe you are missing an other babel plugin ;)
UPDATE 2020-04-17
As it is said for #babel-polyfill
As of Babel 7.4.0, this package has been deprecated in favor of directly including core-js/stable (to polyfill ECMAScript features) and regenerator-runtime/runtime (needed to use transpiled generator functions):
So install npm i core-js and npm i regenerator-runtime
Then in your webpack config file you manage the entry points like that
...
entry: {
bundle: [require.resolve('core-js/stable'), require.resolve('regenerator-runtime/runtime'), paths.srcClient]
},
...
Then you are good to go
I think this is due to the fact that the react does not support ie10. I get an error in ie10 Set in undefined and in ie11 the redux store is not loaded. According to the documentation, the react needs to be imported polyfill globally.
https://reactjs.org/docs/javascript-environment-requirements.html

Webpack 1.15.0 Parse Error: JSX File

I have tried to fix my errors according to some answers. But I can't solve.
I am using webpack 1.15.0 and babel-loader 6.4.1.
Please help me to parse jsx file.
Here is the error message.
ERROR in ./~/react-file-viewer/src/components/file-viewer.jsx Module
parse failed:
E:\code-bucket\university\node_modules\react-file-viewer\src\components\file-viewer.jsx
Unexpected token (74:6) You may need an appropriate loader to handle
this file type. SyntaxError: Unexpected token (74:6)
Here is my webpack.config.js file.
{
var path = require('path');
module.exports = {
entry: './client/js/app.js',
output: {
path: path.resolve('www/build/js'),
filename: 'app.bundle.js',
pathinfo: false
},
module: {
loaders: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react'],
plugins: ['transform-object-rest-spread']
},
exclude: /node_modules/
},
{
test: /\.css$/, // Transform all .css files required somewhere within an entry point...
loaders: ['style-loader', 'css-loader', 'postcss-loader'] // ...with PostCSS
}
]
},
postcss: function() {
return [
require('postcss-import')({ // Import all the css files...
onImport: function (files) {
files.forEach(this.addDependency); // ...and add dependecies from the main.css files to the other css files...
}.bind(this) // ...so they get hot–reloaded when something changes...
}),
require('postcss-simple-vars')(), // ...then replace the variables...
require('postcss-focus')(), // ...add a :focus to ever :hover...
require('autoprefixer')({ // ...and add vendor prefixes...
browsers: ['last 2 versions', 'IE > 8'] // ...supporting the last 2 major browser versions and IE 8 and up...
}),
require('postcss-reporter')({ // This plugin makes sure we get warnings in the console
clearMessages: true
})
];
},
target: "web", // Make web variables accessible to webpack, e.g. window
stats: {
colors: true
},
devtool: 'source-map'
};
}
Here is my package.json file.
{
"name": "university",
"version": "1.0.0",
"description": "Sample Application with React and the Lightning Design System",
"engines": {
"node": "4.2.1"
},
"main": "server.js",
"scripts": {
"webpack": "webpack",
"start": "node server.js",
"bundle": "build-bundle src/apps/ -o dist -v 1.0.0"
},
"author": "Christophe Coenraets <ccoenraets#gmail.com> (http://coenraets.org/)",
"license": "ISC",
"dependencies": {
"autoprefixer": "^7.1.4",
"babel-plugin-transform-object-rest-spread": "^6.3.13",
"bcryptjs": "^2.4.3",
"body-parser": "^1.14.2",
"build-bundle": "^2.0.8",
"compression": "^1.6.1",
"connect-busboy": "0.0.2",
"connect-multiparty": "^2.0.0",
"css-loader": "^0.28.7",
"cssnano": "^3.10.0",
"express": "^4.13.4",
"file-loader": "^0.11.2",
"filesize": "^3.5.10",
"fine-uploader": "^5.15.0",
"fontfaceobserver": "^2.0.13",
"fs": "0.0.1-security",
"fs-extra": "^4.0.2",
"gulp": "^3.9.1",
"json2csv": "^3.11.4",
"loader-utils": "^1.1.0",
"method-override": "^2.3.5",
"moment": "^2.11.2",
"multer": "^1.3.0",
"mysql": "^2.14.1",
"object.assign": "^4.0.4",
"path": "^0.12.7",
"pg": "^4.4.4",
"postcss-cssnext": "^3.0.2",
"postcss-focus": "^2.0.0",
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.6",
"postcss-reporter": "^5.0.0",
"react-addons-css-transition-group": "^15.6.2",
"react-addons-transition-group": "^15.6.2",
"react-animate-height": "^0.10.3",
"react-bootstrap": "^0.31.3",
"react-csv": "^1.0.8",
"react-file-download": "^0.3.5",
"react-file-viewer": "^0.3.48",
"react-fileupload": "^2.4.0",
"react-fine-uploader": "^1.0.7",
"react-html-table-to-excel": "^2.0.0",
"react-redux": "^5.0.6",
"react-router": "^2.0.0-rc5",
"react-strap": "0.0.1",
"react-swipeable-views": "^0.12.8",
"react-transition-group": "^2.2.1",
"react-upload-file": "^2.0.0-beta.6",
"reactstrap": "^4.8.0",
"reactstrap-tether": "^1.3.4",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0",
"sass": "^1.0.0-beta.2",
"style-loader": "^0.18.2",
"write": "^1.0.3",
"write-file": "^1.0.0",
"write-file-p": "^1.0.6"
},
"devDependencies": {
"babel-core": "^6.4.5",
"babel-loader": "^6.4.1",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-3": "^6.3.13",
"history": "^1.17.0",
"postcss": "^6.0.12",
"postcss-simple-vars": "^4.1.0",
"react": "^0.14.9",
"react-addons-linked-state-mixin": "^0.14.7",
"react-dom": "^0.14.9",
"react-onclickoutside": "^4.5.0",
"react-router": "^1.0.3",
"webpack": "^1.15.0"
}
}

Gulp & Webpack compiling React

I am strugling with setting up basic compilation of my React project using Gulp & Webpack
Here is my Gulpfile:
function styles() {
return gulp.src('./src/less/styles.less')
.pipe(less())
.pipe(gulp.dest('./dist'))
.pipe(connect.reload());
}
function copyAssets() {
return gulp.src('./assets/**')
.pipe(gulpCopy('./dist/'))
.pipe(connect.reload());
}
function watchAssets() {
gulp.watch('assets/**/*', copyAssets);
gulp.watch('src/less/**/*.less', styles);
}
function webpackBuildgulp() {
return gulp.src('src/js/index.js')
.pipe(webpack(webpackConfig))
.pipe(gulp.dest('dist/'));
}
gulp.task('default', gulp.parallel(styles, copyAssets, webpackBuildgulp, server, watchAssets));
Here is my Webpack config:
module.exports = () => {
const webpackConfig = {
entry: './src/js/index.js',
module: {
rules: [{
test: /\.jsx$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['es2015', 'stage-0', 'react'],
},
},
}],
},
output: {
path: path.resolve(__dirname, '../dist'),
filename: 'app.js',
publicPath: 'http://localhost:1337/dist/',
},
resolve: {
modules: ['../src/js', 'node_modules'],
extensions: ['', '.js', 'jsx'],
},
plugins: [
new webpack.ProvidePlugin({
jQuery: 'jquery',
$: 'jquery',
}),
],
};
return webpackConfig;
};
Here is package.json deps tree:
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-core": "^6.24.0",
"babel-loader": "^7.0.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.7.7",
"babel-plugin-transform-object-rest-spread": "^6.8.0",
"babel-plugin-transform-react-jsx": "^6.7.5",
"babel-preset-airbnb": "^1.0.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.5.0",
"babelify": "^7.3.0",
"chalk": "^1.1.3",
"connect-modrewrite": "^0.9.0",
"envify": "^3.4.1",
"enzyme": "^2.4.1",
"eslint": "^3.11.1",
"eslint-config-airbnb": "^13.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.8.0",
"gulp": "github:gulpjs/gulp#4.0",
"gulp-callback": "0.0.3",
"gulp-connect": "^5.0.0",
"gulp-imagemin": "^3.0.3",
"gulp-less": "^3.1.0",
"gulp-uglify": "^2.0.0",
"gulp-watch": "^4.3.9",
"gutil": "^1.6.4",
"husky": "^0.11.6",
"isparta": "^4.0.0",
"jasmine-core": "^2.4.1",
"jsdom": "^8.4.1",
"karma": "^0.13.19",
"karma-babel-preprocessor": "^6.0.1",
"karma-browserify": "^5.0.0",
"karma-chrome-launcher": "^0.2.2",
"karma-coverage": "^1.1.0",
"karma-jasmine": "^0.3.6",
"karma-nyan-reporter": "^0.2.4",
"karma-phantomjs-launcher": "^1.0.0",
"karma-sinon": "^1.0.4",
"less": "^2.6.1",
"less-plugin-autoprefix": "^1.5.1",
"less-plugin-clean-css": "^1.5.1",
"phantomjs-polyfill-object-assign": "0.0.2",
"phantomjs-prebuilt": "^2.1.4",
"react-addons": "^0.9.1-deprecated",
"react-addons-shallow-compare": "15.4.0",
"react-addons-test-utils": "15.4.0",
"react-asset-loader": "0.0.1",
"react-images": "^0.5.1",
"react-test-renderer": "15.4.0",
"require-dir": "^0.3.0",
"sinon": "^1.17.4",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.7.0",
"webpack-dev-middleware": "^1.10.0",
"webpack-stream": "^3.2.0",
"when": "^3.7.7"
},
"dependencies": {
"animate.css": "^3.5.1",
"axios": "^0.12.0",
"classnames": "^2.2.5",
"es6-promise": "^3.2.1",
"fullcalendar": "3.3.1",
"fullcalendar-scheduler": "1.5.0",
"intl": "^1.2.4",
"jquery": "2.1.4",
"jquery-timepicker": "^1.3.3",
"lodash": "^4.13.1",
"moment": "2.18.1",
"moment-range": "^3.0.2",
"qtip2": "^3.0.3",
"rc-calendar": "^7.6.5",
"rc-time-picker": "^2.2.2",
"react": "15.4.0",
"react-animated-number": "^0.4.2",
"react-countup": "^1.3.0",
"react-datepicker": "^0.41.1",
"react-dom": "15.4.0",
"react-dropzone": "^3.5.3",
"react-geosuggest": "^1.24.1",
"react-google-maps": "^4.11.0",
"react-google-tag-manager": "^1.1.2",
"react-helmet": "^3.1.0",
"react-imageloader": "^2.1.0",
"react-intl": "^2.1.3",
"react-maskedinput": "^3.2.4",
"react-redux": "^5.0.0",
"react-redux-toastr": "^3.8.5",
"react-router": "^2.5.2",
"react-scrollbar": "^0.4.1",
"react-sortable": "1.2.0",
"react-sparklines": "^1.6.0",
"react-tabs": "^0.7.0",
"react-typist": "^1.1.0",
"redux": "^3.5.2",
"redux-form": "^6.3.2",
"redux-logger": "^2.6.1",
"redux-mock-store": "^1.1.2",
"redux-thunk": "^2.1.0",
"riek": "^1.0.4",
"slick-carousel": "^1.6.0",
"spid-sdk-js": "^2.1.7",
"vivus": "^0.3.1"
},
However when I trie to compile my project typing gulp I get the following error:
Module parse failed: /src/js/index.js Unexpected token (42:2)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (42:2)
Here is the index.js file:
import ReactDOM from 'react-dom';
import React from 'react';
import { Provider } from 'react-redux';
import { Router, browserHistory } from 'react-router';
import { IntlProvider } from 'react-intl';
import ReduxToastr from 'react-redux-toastr';
import createStore from './store';
import { SIGNIN_USER, getCurrentUser } from './actions/auth';
import { getSalonsBasicInfo } from './actions/landingPage';
import { stuff } from './middleware/stuff';
import { checkSalon } from './actions/salon';
import routes from './routes';
import translations from './translations/en';
if (!window.Intl) {
require('intl');
}
const store = createStore();
const access_token = localStorage.getItem('access_token');
const refresh_token = localStorage.getItem('refresh_token');
store.dispatch({
type: INIT,
});
if (access_token || refresh_token) {
store.dispatch({
type: SIGNIN_USER,
});
store.dispatch(getCurrentUser());
store.dispatch(checkSalon());
}
localStorage.setItem('debug', false);
ReactDOM.render(
<Provider store={store}>
<div>
<ReduxToastr
timeOut={4000}
newestOnTop={false}
position="top-center"
/>
<IntlProvider locale={'en-US'} messages={translations}>
<Router history={browserHistory} routes={routes} />
</IntlProvider>
</div>
</Provider>,
document.getElementById('app'),
);
Someway, somehow, Babel fails to understand React code and doesnt compile it.
However when I run Babel manually:
babel src/js/index.js --presets es2015,react
It works perfectly.
What am I doing wrong in my Webpack configuration ?
Your babel-loader is only testing for .jsx files and you have saved your index as a .js file. Change test to test: /\.(js|jsx)$/, and see if that helps.
module: {
rules: [{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['es2015', 'stage-0', 'react'],
},
},
}],
}

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.

React app crashes in IE11

We have a react app based on the react-production-starter boilerplate.
Our dev build runs fine in IE11, but for some reason our production build doesn't.
We get the following error:
Minified React error #109; visit http://facebook.github.io/react/docs/error-decoder.html?invariant=109&args[]=t for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
Here are the project dependencies:
"dependencies": {
"actual": "0.2.0",
"async": "2.1.4",
"attr-accept": "1.1.0",
"aws-sdk": "2.7.11",
"babel-register": "6.18.0",
"bcrypt": "1.0.0",
"body-parser": "1.15.2",
"canvas": "1.6.2",
"clipboard": "1.5.15",
"clor": "2.0.2",
"color-convert": "1.8.2",
"color-thief": "2.2.2",
"columnify": "1.5.4",
"compression": "1.6.2",
"cookie-parser": "1.4.3",
"cors": "2.8.1",
"couchbase": "2.2.4",
"couchnode": "4.3.4",
"cross-env": "3.1.3",
"debug": "2.3.3",
"dockerode": "2.3.1",
"dotenv": "2.0.0",
"elasticsearch": "12.1.0",
"email-templates": "2.5.4",
"express": "4.14.0",
"express-useragent": "1.0.4",
"fluent-ffmpeg": "2.1.0",
"geoip-lite": "1.1.8",
"glamor": "2.20.12",
"gsap": "1.19.0",
"handlebars": "4.0.6",
"history": "4.4.1",
"hpp": "0.2.1",
"image-size": "0.5.0",
"js2xmlparser": "2.0.2",
"json2csv": "3.7.2",
"kue": "0.11.5",
"lodash": "4.17.2",
"material-ui": "0.16.4",
"moment": "2.17.1",
"mongo-oplog": "cayasso/mongo-oplog#eba0c4fe6698854cd85442ef12da97fd74282dbc",
"mongodb": "2.2.16",
"morgan": "1.7.0",
"ms": "0.7.2",
"multer": "1.2.0",
"node-cache": "4.1.0",
"node-schedule": "1.2.0",
"normalize.css": "4.2.0",
"npm-run-all": "3.1.2",
"open-graph": "0.2.2",
"passport": "0.3.2",
"passport-facebook": "2.1.1",
"passport-google-oauth": "1.0.0",
"passport-local": "1.0.0",
"promise": "7.1.1",
"pug": "2.0.0-beta6",
"react": "15.4.1",
"react-addons-css-transition-group": "15.4.1",
"react-addons-shallow-compare": "15.4.1",
"react-anything-sortable": "matanasa/react-anything-sortable",
"react-avatar-editor": "6.1.0",
"react-canvas": "1.2.1",
"react-click-outside": "tj/react-click-outside",
"react-color": "2.10.0",
"react-confirm": "0.1.14",
"react-cropper": "0.10.0",
"react-custom-scrollbars": "4.0.0",
"react-dom": "15.4.1",
"react-ga": "2.1.2",
"react-gsap-enhancer": "0.3.0",
"react-helmet": "3.2.3",
"react-infinite-scroll-component": "Hazantip/react-infinite-scroll-component#master",
"react-key-handler": "0.3.0",
"react-masonry-component": "4.4.0",
"react-paginate": "4.0.0",
"react-redux": "4.4.6",
"react-rnd": "4.2.0",
"react-router": "3.0.0",
"react-router-redux": "4.0.7",
"react-stickydiv": "3.4.19",
"react-swipeable": "3.7.0",
"react-tap-event-plugin": "2.0.1",
"react-text-input": "0.0.8",
"react-timer-hoc": "2.0.2",
"react-virtualized": "8.7.1",
"redial": "0.5.0",
"redlock": "2.1.0",
"redux": "3.6.0",
"redux-form": "6.2.1",
"redux-form-validation": "0.0.8",
"redux-logger": "2.7.4",
"redux-thunk": "2.1.0",
"request": "2.79.0",
"seamless-immutable": "7.0.1",
"sharp": "0.17.0",
"socketcluster-client": "5.1.1",
"sortablejs": "1.5.0-rc1",
"source-map-support": "0.4.6",
"ssh2": "0.5.4",
"superagent": "3.1.0",
"urijs": "1.18.4",
"vimeo": "1.2.0"
},
"devDependencies": {
"assets-webpack-plugin": "3.5.0",
"babel-cli": "6.18.0",
"babel-core": "6.18.2",
"babel-eslint": "7.1.1",
"babel-loader": "6.2.8",
"babel-plugin-transform-decorators-legacy": "1.3.4",
"babel-plugin-transform-react-constant-elements": "6.9.1",
"babel-plugin-transform-react-inline-elements": "6.8.0",
"babel-polyfill": "6.16.0",
"babel-preset-es2015": "6.18.0",
"babel-preset-react": "6.16.0",
"babel-preset-stage-0": "6.16.0",
"babel-register": "6.18.0",
"chai": "3.5.0",
"chai-http": "3.0.0",
"chalk": "1.1.3",
"core-decorators": "0.14.0",
"css-loader": "0.26.1",
"eslint": "3.11.1",
"eslint-config-airbnb": "13.0.0",
"eslint-loader": "1.6.1",
"eslint-plugin-import": "2.2.0",
"eslint-plugin-jsx-a11y": "2.2.3",
"eslint-plugin-react": "6.8.0",
"extract-text-webpack-plugin": "1.0.1",
"json-loader": "0.5.4",
"mocha": "3.2.0",
"nodemon": "1.11.0",
"npm-check": "5.4.0",
"opn": "4.0.2",
"react-copy-to-clipboard": "4.2.3",
"style-loader": "0.13.1",
"stylus": "0.54.5",
"stylus-loader": "2.4.0",
"webpack": "1.14.0",
"webpack-dev-middleware": "1.8.4",
"webpack-hot-middleware": "2.13.2"
},
Our .babelrc:
{
"presets": ["es2015", "react", "stage-0"],
"plugins": ["transform-decorators-legacy"]
}
Our webpack build:
const webpack = require('webpack');
const AssetsPlugin = require('assets-webpack-plugin');
const CONFIG = require('./webpack.base');
const { CLIENT_ENTRY, CLIENT_OUTPUT } = CONFIG;
module.exports = {
'devtool': 'source-map',
'entry': {
'main': [require.resolve('./polyfills'), CLIENT_ENTRY],
'vendor': [
'react',
'react-dom',
'react-router',
'redux',
'react-redux',
],
},
'output': {
'filename': '[name]_[chunkhash].js',
'chunkFilename': '[name]_[chunkhash].js',
'publicPath': '/assets/',
'path': CLIENT_OUTPUT,
},
'plugins': [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production'),
},
'__DEV__': false,
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor_[hash].js', Infinity),
new AssetsPlugin({ 'filename': 'assets.json' }),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
'compressor': {
'screw_ie8': true,
'warnings': false,
},
'mangle': {
'screw_ie8': true,
},
'output': {
'comments': false,
'screw_ie8': true,
},
}),
new webpack.NoErrorsPlugin(),
],
'resolve': {
'extensions': ['', '.js', '.styl'],
},
'module': {
'loaders': [
{
'test': /\.js$/,
'loader': 'babel',
'query': {
'cacheDirectory': true,
'presets': ['es2015', 'react', 'stage-0'],
'plugins': ['transform-decorators-legacy', 'transform-react-constant-elements', 'transform-react-inline-elements'],
},
'exclude': /(node_modules)/,
},
{
'test': /\.json$/,
'loader': 'json',
},
{
'test': /\.styl|\.css$/,
'loader': 'style-loader!css-loader!stylus-loader',
},
],
},
'stylus': {
'preferPathResolver': 'webpack',
},
};
Has anyone had similar issues with IE out there?
Remove transform-react-inline-elements from plugins list of babel-loader in webpack config file.
This requires ES6 Symbol, but it is not present in IE11.

Resources