Missing Semicolon Error in node js webpack - node.js

I am getting semicolon error in one of my json files while building my project using webpack, my json files are formated and still giving me this error. I am using these
"#babel/cli": "^7.6.2",
"#babel/core": "^7.5.5",
"#babel/preset-env": "^7.20.2",
"babel-core": "^6.26.3",
"babel-eslint": "^10.1.0",
"babel-loader": "^9.1.0",
"eslint": "^7.0.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-loader": "^4.0.2",
"eslint-plugin-import": "^2.18.2",
"nodemon": "^2.0.20",
"nodemon-webpack-plugin": "^4.3.1",
"terser-webpack-plugin": "5.3.6",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
"webpack-node-externals": "^3.0.0"
here is the error:
ERROR in ./src/express/routes/channels/libs/etsy/etsy.config.json
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: C:\src\express\routes\channels\libs\etsy\etsy.config.json: Missing semicolon. (2:7)
1 | {
> 2 | "env": "development",
| ^
3 | "shopId": "FabricAndSewing",
4 | "key": "65hgx4sow7ih76bb9sir78f7",
5 | "secret": "8eoy84mw8u",
at instantiate (C:\Excersys\FASAPI3\node_modules\#babel\parser\lib\index.js:67:32)
at constructor (C:\Excersys\FASAPI3\node_modules\#babel\parser\lib\index.js:364:12)
webpackConfig.js
import * as path from "path";
import Dotenv from "dotenv-webpack";
import nodeExternals from "webpack-node-externals";
import NodemonPlugin from "nodemon-webpack-plugin";
const __dirname = path.resolve(path.dirname(""));
const config = (env, argv) => ({
entry: {
server: "./src/index.js",
},
output: {
path: path.join(__dirname, "dist"),
publicPath: "/",
filename: "[name].js",
},
mode: argv.mode,
target: "node",
node: {
__dirname: false,
__filename: false,
},
externals: [nodeExternals()],
module: {
rules: [
{
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["#babel/preset-env"],
},
},
},
],
parser: {
javascript: {
// ...
commonjsMagicComments: true,
},
},
},
plugins: [new NodemonPlugin(), new Dotenv()],
resolve: {
extensions: [".js", ".json", ".wasm"],
},
});
export default config;
.eslintrc.js
module.exports = {
env: {
browser: true,
node: true,
es2022: true,
},
// extends: ['airbnb-base'],
// globals: {
// Atomics: 'readonly',
// SharedArrayBuffer: 'readonly'
// },
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
},
rules: {
semi: "off",
},
};
I tried different webpack and eslint configs but nothing worked

Related

Webpack issue when update 4.x to 5.x

I have a problem when i updated in my project the webpack package to V5.x.
Here is the error :
webpack-hot-client: entry Object values must be an Array or Function. Please check your webpack config.
Here is my package.json :
"*.css",
"*.scss",
"*.sass" ], "main": "index.js", "scripts": {
"analyze": "bnr clean:build && bnr analyze",
"build:all": "bnr clean:build && bnr build:client && bnr build:server",
"build:client": "bnr clean:build && bnr build:client",
"build:server": "bnr clean:build && bnr build:server",
"clean": "bnr clean:build",
"dev": "bnr dev",
"docker": "yarn docker:build && yarn docker:start && yarn docker:status",
"docker:build": "docker-compose build --no-cache",
"docker:start": "docker-compose up -d",
"docker:status": "docker-compose logs -f -t",
"flow": "bnr flow",
"flow:stop": "bnr flow:stop",
"lint": "npm-run-all lint:js lint:style lint:json",
"lint:js": "bnr lint:js",
"lint:style": "bnr lint:style",
"lint:json": "bnr lint:json",
"prod": "bnr build:client && bnr build:server && bnr start",
"start": "bnr start",
"sitemap": "node sitemap-generator.js" }, "betterScripts": {
"analyze": {
"command": "npx webpack -p --progress --hide-modules --config ./tools/webpack/production.client.babel.js",
"env": {
"NODE_ENV": "analyze"
}
},
"build:client": {
"command": "npx webpack --hide-modules --config ./tools/webpack/production.client.babel.js && npx gulp --gulpfile
tools/gulpfile.js",
"env": {
"NODE_ENV": "production"
}
},
"build:server": {
"command": "npx babel ./src -d ./dist --copy-files && npx webpack --hide-modules --config
./tools/webpack/production.server.babel.js",
"env": {
"NODE_ENV": "production"
}
},
"clean:build": {
"command": "rimraf ./public/assets && rimraf ./public/webpack-assets.json"
},
"dev": {
"command": "nodemon ./index.js",
"env": {
"NODE_PATH": "./src",
"NODE_ENV": "development",
"PORT": 3000
}
},
"flow": {
"command": "npx flow"
},
"flow:stop": {
"command": "npx flow stop"
},
"lint:js": {
"command": "npx eslint --fix ./src ./tools ./index.js"
},
"lint:json": {
"command": "npx prettier --write src/**/**/*.json"
},
"lint:style": {
"command": "npx stylelint --fix ./src/**/*.css, ./src/**/*.scss"
},
"start": {
"command": "node ./index.js",
"env": {
"NODE_PATH": "./dist",
"NODE_HOST": "0.0.0.0",
"NODE_ENV": "production",
"PORT": 8080
}
} }, "husky": {
"hooks": {
"pre-commit": "lint-staged"
} }, "lint-staged": {
"*.{js,jsx}": "eslint --fix",
"*.{json,md}": "prettier --write",
"*.{scss,sass}": "stylelint --syntax=scss" }, "nodemonConfig": {
"watch": [
"src/server.js",
"src/handler.js",
"src/utils/renderHtml.js",
"src/theme/variables.scss"
] }, "browserslist": [
"> 1%",
"last 3 versions" ], "eslintIgnore": [
"tools/flow",
"public/assets" ], "dependencies": {
"#babel/cli": "^7.14.5",
"#babel/plugin-proposal-export-namespace-from": "^7.5.2",
"#fortawesome/fontawesome-free": "^5.15.1",
"#hapi/address": "^4.1.0",
"#koa/router": "^10.1.1",
"#loadable/component": "^5.10.2",
"#loadable/server": "^5.10.2",
"#tweenjs/tween.js": "^18.3.1",
"ansi-regex": "^6.0.1",
"axios": "^0.23.0",
"bootstrap": "^5.1.3",
"chalk": "^4.1.2",
"classnames": "^2.2.6",
"d3-ease": "^3.0.1",
"del": "^6.0.0",
"esm": "^3.2.25",
"glob-parent": "^6.0.2",
"gulp": "^4.0.2",
"gulp-cache": "^1.1.3",
"gulp-imagemin": "^8.0.0",
"gulp-postcss": "^9.0.0",
"gulp-rename": "^2.0.0",
"i18next": "^21.3.2",
"i18next-browser-languagedetector": "^6.1.2",
"i18next-node-fs-backend": "^2.1.3",
"i18next-resource-store-loader": "^0.1.2",
"i18next-xhr-backend": "^3.1.2",
"imagemin-mozjpeg": "^9.0.0",
"imagemin-pngquant": "^9.0.2",
"koa": "^2.8.1",
"koa-bodyparser": "^4.2.1",
"koa-compress": "^5.1.0",
"koa-favicon": "^2.0.1",
"koa-helmet": "^6.1.0",
"koa-i18next-detector": "^0.7.2",
"koa-i18next-middleware": "^1.1.12",
"koa-i18next-middleware-fixed": "^1.1.10-b3",
"koa-morgan": "^1.0.1",
"koa-mount": "^4.0.0",
"koa-router": "^10.1.1",
"koa-static": "^5.0.0",
"koa-webpack": "^6.0.0",
"koa-webpack-server": "^0.2.4",
"micro-dash": "^8.1.0",
"moment": "^2.24.0",
"p-min-delay": "^4.0.1",
"pm2": "^5.1.2",
"qs": "^6.8.0",
"rc-animate": "^3.1.1",
"rc-queue-anim": "^2.0.0",
"rc-scroll-anim": "^2.6.1",
"rc-tween-one": "^2.6.3",
"react": "^17.0.2",
"react-bootstrap": "^1.0.0-beta.8",
"react-dom": "npm:#hot-loader/react-dom#^16.8.6",
"react-global-configuration": "^1.4.1",
"react-gtm-module": "^2.0.11",
"react-helmet": "^6.1.0",
"react-i18next": "^11.12.0",
"react-icons": "^4.3.1",
"react-motion": "^0.5.2",
"react-player": "^2.9.0",
"react-pose": "^4.0.8",
"react-router": "^5.0.1",
"react-router-config": "^5.0.1",
"react-router-dom": "^5.0.1",
"react-router-last-location": "^2.0.1",
"react-router-sitemap": "^1.2.0",
"react-spring": "^9.3.0",
"react-tilt": "^0.1.4",
"react-typist": "^2.0.5",
"react-youtube": "^7.9.0",
"sass-resources-loader": "^2.0.1",
"serialize-javascript": "^6.0.0",
"styled-components": "^5.3.1",
"terser-webpack-plugin": "^5.2.4" }, "devDependencies": {
"#babel/core": "^7.6.0",
"#babel/node": "^7.14.5",
"#babel/plugin-proposal-class-properties": "^7.5.5",
"#babel/plugin-proposal-export-default-from": "^7.5.2",
"#babel/plugin-proposal-optional-chaining": "^7.6.0",
"#babel/plugin-syntax-dynamic-import": "^7.2.0",
"#babel/preset-env": "^7.14.5",
"#babel/preset-flow": "^7.0.0",
"#babel/preset-react": "^7.14.5",
"#babel/register": "^7.6.0",
"#babel/runtime": "^7.6.0",
"#loadable/babel-plugin": "^5.10.0",
"#loadable/webpack-plugin": "^5.7.1",
"asset-require-hook": "^1.2.0",
"babel-eslint": "^10.0.3",
"babel-loader": "^8.0.6",
"babel-plugin-dynamic-import-node": "^2.3.0",
"babel-plugin-istanbul": "^6.1.1",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"babel-plugin-transform-remove-console": "^6.9.4",
"better-npm-run": "^0.1.1",
"compression-webpack-plugin": "^9.0.0",
"core-js": "3",
"css-loader": "^6.4.0",
"css-modules-require-hook": "^4.2.3",
"cssnano": "^5.0.8",
"eslint": "^8.0.1",
"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-webpack": "^0.13.1",
"eslint-plugin-flowtype": "^6.1.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.14.3",
"eslint-plugin-react-hooks": "^4.2.0",
"file-loader": "^6.2.0",
"flow-bin": "^0.162.0",
"friendly-errors-webpack-plugin": "^1.7.0",
"html-minifier": "^4.0.0",
"husky": "^7.0.2",
"imagemin-webpack-plugin": "^2.4.2",
"lint-staged": "^11.2.3",
"mini-css-extract-plugin": "^2.4.2",
"nodemon": "^2.0.13",
"normalize.css": "^8.0.1",
"npm-run-all": "^4.1.5",
"optimize-css-assets-webpack-plugin": "^6.0.1",
"postcss": "^8.3.9",
"postcss-loader": "^6.2.0",
"postcss-preset-env": "^6.7.0",
"prettier": "^2.4.1",
"react-dev-utils": "^11.0.4",
"react-hot-loader": "^4.12.13",
"react-router-sitemap-generator": "^0.0.8",
"react-test-renderer": "^17.0.2",
"rimraf": "^3.0.0",
"sass": "^1.43.2",
"sass-loader": "^12.2.0",
"static-site-generator-webpack-plugin": "^3.4.2",
"stylelint": "^13.13.1",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-recommended-scss": "^4.3.0",
"stylelint-config-standard": "^22.0.0",
"stylelint-scss": "^3.10.1",
"url-loader": "^4.1.1",
"webpack": "^5.58.2",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-cli": "4.9.1",
"webpack-dev-middleware": "^5.2.1",
"webpack-hot-middleware": "^2.25.0",
"webpack-manifest-plugin": "^4.0.2",
"webpack-merge": "^5.8.0",
"webpack-node-externals": "^3.0.0" }, "engines": {
"node": ">=8",
"npm": ">=5" } }```
Here is my base.config.js of webpack :
import webpack from 'webpack'
import { WebpackManifestPlugin } from 'webpack-manifest-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import FriendlyErrorsWebpackPlugin from 'friendly-errors-webpack-plugin'
import LoadablePlugin from '#loadable/webpack-plugin'
import config from './config'
const nodeEnv = process.env.NODE_ENV || 'development'
const isDev = nodeEnv === 'development'
const getPlugins = () => {
const plugins = [
new WebpackManifestPlugin({
fileName: path.resolve(process.cwd(), 'public/webpack-assets.json'),
filter: file => file.isInitial
}),
new MiniCssExtractPlugin({
filename: `${config.cssFileName}.css`,
chunkFilename: `${config.cssChunkFileName}.css`,
ignoreOrder: true
}),
// Setup environment variables for client
new webpack.EnvironmentPlugin({ NODE_ENV: JSON.stringify(nodeEnv) }),
// Setup global variables for client
new webpack.DefinePlugin({
__CLIENT__: true,
__SERVER__: false,
__DEV__: isDev
}),
new LoadablePlugin({ filename: '../loadable-stats.json', writeToDisk: true })
]
if (isDev) {
plugins.push(new FriendlyErrorsWebpackPlugin())
}
return plugins
}
// Webpack configuration
module.exports = {
mode: isDev ? 'development' : 'production',
devtool: isDev ? 'eval-source-map' : 'hidden-source-map',
context: path.resolve(process.cwd()),
entry: ['webpack-hot-middleware/client','./src/index.js'],
optimization: {
splitChunks: {
chunks: 'async'
}
},
output: {
path: path.resolve(process.cwd(), 'public/assets'),
publicPath: '/assets/',
filename: `${config.fileName}.js`,
chunkFilename: `${config.chunkFileName}.js`,
pathinfo: isDev
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
options: { cacheDirectory: isDev }
},
{
test: /\.css$/,
include: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css',
options: {
importLoaders: 1,
modules: false,
sourceMap: true
}
},
{ loader: 'postcss', options: { sourceMap: true } }
]
},
{
test: /\.(scss|sass)$/,
exclude: path.resolve(__dirname, '..', '..', 'src/theme/'),
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: isDev,
reloadAll: true
}
},
{
loader: 'css',
options: {
importLoaders: 2,
modules: {
localIdentName: config.cssModulesIdentifier,
context: path.resolve(process.cwd(), 'src')
},
sourceMap: true
}
},
{ loader: 'postcss', options: { sourceMap: true } },
{
loader: 'sass',
options: {
sassOptions: {
outputStyle: 'expanded'
},
sourceMap: true
}
},
{
loader: 'sass-resources',
options: {
resources: path.resolve(process.cwd(), 'src/theme/_include.scss')
}
}
]
},
{
test: /\.(scss|sass)$/,
include: path.resolve(__dirname, '..', '..', 'src/theme/'),
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: isDev,
reloadAll: true
}
},
{
loader: 'css',
options: {
importLoaders: 2,
modules: false,
sourceMap: true
}
},
{ loader: 'postcss', options: { sourceMap: true } },
{
loader: 'sass',
options: {
sassOptions: {
outputStyle: 'expanded'
},
sourceMap: true
}
}
]
},
{
test: path.resolve(process.cwd(), 'src/locales'),
loader: 'i18next-resource-store-loader'
},
{
test: /\.(woff2?|ttf|eot|svg|otf)$/,
loader: 'url',
options: { limit: 10240, name: config.staticFilesName }
},
{
test: /\.(gif|png|jpe?g|webp)$/,
// Any image below or equal to 10Kb will be converted to base64
loader: 'url',
options: { limit: 10240, name: config.staticFilesName }
},
{
test: /\.(mp3|mp4|ogv)$/,
loader: 'file',
options: { name: config.staticFilesName }
}
]
},
plugins: getPlugins(),
resolveLoader: {
mainFields: ['loader']
},
resolve: {
modules: ['src', 'node_modules'],
descriptionFiles: ['package.json'],
extensions: ['.js', '.jsx', '.json'],
fallback:{
fs: false,
vm: false,
net: false,
tls: false
}
},
cache: isDev,
stats: { children: false }
I tried a lot of things and i fixed a lot of issues but for me the entry is an Array, so i don't know why i got this error.
Here there is my server.js (he launches all the programs) :
import logger from 'koa-morgan'
import Koa from 'koa'
import bodyParser from 'koa-bodyparser'
import compression from 'koa-compress'
import helmet from 'koa-helmet'
import querystring from 'qs'
import Router from '#koa/router'
import favicon from 'koa-favicon'
import axios from 'axios'
import chalk from 'chalk'
import mount from 'koa-mount'
import serve from 'koa-static'
import Backend from 'i18next-node-fs-backend'
import i18n from 'i18next'
import i18nextMiddleware from 'koa-i18next-middleware-fixed'
import LanguageDetector from 'koa-i18next-detector'
import c from './config'
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0
const app = new Koa()
const router = new Router()
const sendMessage = body =>
new Promise((resolve, reject) => {
const config = {
maxRedirects: 0,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}
axios
.post(
'https://go.pardot.com/l/138941/2019-07-22/2h6dgb',
querystring.stringify({ ...body, privacy: true }),
config
)
.then(result => {
resolve(result.status === 200)
})
.catch(e => {
reject(new Error(e))
})
})
const lngDetector = new LanguageDetector()
i18n
.use(Backend)
.use(lngDetector)
.init(
{
debug: false,
fallbackLng: 'fr',
saveMissing: false,
react: {
useSuspense: false
},
detection: {
order: ['path', 'navigator']
},
interpolation: {
escapeValue: false,
formatSeparator: ',',
format: (value, format) => {
if (format === 'uppercase') return value.toUpperCase()
return value
}
},
preload: ['fr'],
load: 'languageOnly',
ns: [
'global',
'landing_references',
'landing_expertises',
'home',
'references',
'expertises',
'contact',
'about',
'partners',
'team'
],
defaultNS: 'global',
backend: {
loadPath: `${path.resolve(process.cwd(), 'src')}/locales/{{lng}}/{{ns}}.json`
}
},
async () => {
// Use helmet to secure Express with various HTTP headers
app.use(helmet())
app.use(bodyParser())
// Compress all requests
app.use(compression())
// Use for http request debug (show errors only)
app.use(logger('dev', { skip: ctx => ctx.status < 400 }))
app.use(favicon(path.resolve(process.cwd(), 'public/favicon.ico')))
app.use(i18nextMiddleware.getHandler(i18n, { locals: 'lng' }))
// Docker serve static trough nginx for better performance
if (!__DOCKER__) {
console.log(chalk.magenta('==> 🐌 Serve statics with koa'))
app.use(mount('/locales', serve(path.resolve(process.cwd(), 'src/locales'))))
app.use(serve(path.resolve(process.cwd(), 'public')))
}
if (__DEV__) {
app.use(mount('/images', serve(path.resolve(process.cwd(), 'src/images'))))
/* Run express as webpack dev server */
const webpack = require('webpack')
const webpackConfig = require('../tools/webpack/base.config')
const compiler = webpack(webpackConfig)
const koaWebpack = require('koa-webpack')
new webpack.ProgressPlugin().apply(compiler)
const options = {
compiler,
devMiddleware: {
publicPath: webpackConfig.output.publicPath,
headers: { 'Access-Control-Allow-Origin': '*' },
hot: true,
writeToDisk: false,
quiet: true, // Turn it on for friendly-errors-webpack-plugin
noInfo: true,
stats: 'minimal',
serverSideRender: true
}
}
const middleware = await koaWebpack(options)
app.use(middleware)
}
router
.post('/contact', async ctx => {
try {
await sendMessage(ctx.request.body)
ctx.body = {
message: 'Votre message a bien été envoyé'
}
ctx.status = 200
} catch (e) {
ctx.body = {
message: 'Une erreur est survenue'
}
ctx.status = 500
}
})
.get('/', async ctx => {
ctx.status = 302
return ctx.redirect(`/${ctx.request.language}`)
})
.get('*', async (ctx, next) => {
return require('./render')(ctx, next)
})
app.use(router.routes()).use(router.allowedMethods())
if (c.port) {
app.listen(c.port, c.host, err => {
const url = `http://${c.host}:${c.port}`
if (err) console.error(chalk.red(`\n==> Error happen ${err}`))
console.info(chalk.green(`\n==> 🌎 Listening at ${url}`))
})
} else {
console.error(chalk.red('\n==> Error : No PORT environment variable has been specified'))
}
}
)
UPDATE :
I put some console.log in the compiler file :
for (const key of Object.keys(entry)) {
const value = entry[key];
console.log(entry)
console.log(value)
console.log(Array.isArray(Object.values(value)))
if (!Array.isArray(value)) {
throw new TypeError(
'webpack-hot-client: `entry` Object values must be an Array or Function. Please check your webpack config.'
);
Console.log return this :
main: { import: [ 'webpack-hot-middleware/client', './src/index.js' ] }
}
{ import: [ 'webpack-hot-middleware/client', './src/index.js' ] }
true
So i think that there is a problem with the declaration of variable, because we have to do an Object.values() to get the array.
So idk what can i do to resolve the problem, i will not change the dependencies files...
Thx for your time and your response!
Regards
It might not be the right example to your situation, but they made some internal changes to the webpack structure:
entry: {} allows an empty object now (to allow to use plugins to add entries)
here's one of the newer examples I found:
module.exports = {
entry: {
about: { import: './about.js', filename: 'pages/[name][ext]' },
},
};
Source: Webpack v5 internal changes: Entry
I found the error. WebPack Hot Client is not update for the last version of webpack (5.x). If you use Webpack Hot Client, you have to use version 4 of Webpack.
Regards

Upraded Webpack 4 to 5 : Build stalls at 10% building 0/1 entries 1/1 dependencies 0/1 modules

I am upgrading my webpack from 4 to 5 , when i run webpack command
webpack --progress --config webpack.config.js
the progress stalls at
Build stalls at 10% building 0/1 entries 1/1 dependencies 0/1 modules.
This was working fine till i was using webpack 4. I have updated the rules as per the new format for respective headers. THer is no error or warning that printed on the console. It just stalls.
Please find my package.json file
{
"name": "deploy",
"version": "0.0.0",
"dependencies": {
"#khanacademy/react-multi-select": "^0.3.3",
"axios": "^0.21.1",
"backbone": "1.2.3",
"bootstrap": "^4.5.3",
"bootstrap-select": "^1.13.12",
"d3": "^3.3.11",
"eonasdan-bootstrap-datetimepicker": "4.17.47",
"file-saver": "1.3.3",
"formsy-react": "0.19.5",
"globalize": "^1.4.2",
"highcharts": "^9.1.0",
"intl-tel-input": "^17.0.12",
"jquery": "^3.5.1",
"jquery-contextmenu": "2.7.1",
"jquery-jsonview": "1.2.3",
"jstree": "3.3.7",
"leaflet": "1.3.4",
"less": "2.3.1",
"moment": "^2.29.1",
"noVNC": "git://github.com/novnc/noVNC.git#v0.6.2",
"popper.js": "^1.16.1",
"prop-types": "^15.7.2",
"rc-slider": "8.6.9",
"react": "^16.13.1",
"react-codemirror": "1.0.0",
"react-custom-scrollbars": "4.2.1",
"react-dnd": "^14.0.2",
"react-dnd-html5-backend": "^14.0.0",
"react-dom": "^16.13.1",
"react-dropzone": "3.13.4",
"react-json-editor-ajrm": "^2.5.13",
"react-modal": "^3.11.2",
"react-redux": "^7.2.1",
"react-table": "^7.7.0",
"react-tabs": "^3.1.1",
"react-tag-autocomplete": "^6.1.0",
"react-tagsinput": "^3.19.0",
"react-transition-group": "1.2.0",
"react-widgets": "^4.4.11",
"react-widgets-globalize": "^5.0.20",
"react-widgets-moment": "^4.0.27",
"recharts": "^2.0.0-beta.1",
"redux": "^4.0.5",
"redux-form": "^8.3.6",
"redux-thunk": "^2.3.0",
"save": "^2.4.0",
"text-security": "^1.2.0",
"why-did-you-update": "^1.0.8"
},
"browserslist": [
"defaults",
"ie >= 9",
"Firefox >= 45",
"Chrome >= 48",
"Safari >= 10"
],
"devDependencies": {
"#babel/cli": "7.14.3",
"#babel/core": "7.14.3",
"#babel/plugin-proposal-class-properties": "7.2.1",
"#babel/plugin-proposal-decorators": "7.1.6",
"#babel/plugin-proposal-object-rest-spread": "7.0.0",
"#babel/preset-env": "^7.8.4",
"#babel/preset-react": "^7.8.3",
"#babel/preset-stage-1": "7.0.0-beta.40",
"#storybook/react": "^6.2.9",
"babel-eslint": "^10.0.3",
"babel-jest": "^26.6.3",
"babel-loader": "8.2.2",
"babel-plugin-transform-decorators-legacy": "1.3.5",
"copy-webpack-plugin": "^9.0.0",
"cross-env": "^7.0.3",
"css-loader": "^5.2.4",
"dust-loader": "1.3.0",
"dustjs-helpers": "1.7.4",
"dustjs-linkedin": "^2.7.5",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-plugin-flowtype": "^4.6.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.18.3",
"eslint-plugin-react-hooks": "^1.7.0",
"expose-loader": "0.7.5",
"file-loader": "2.0.0",
"jest": "^26.6.3",
"less-loader": "4.1.0",
"lodash": "^4.17.21",
"mini-css-extract-plugin": "1.6.0",
"npm-run-all": "4.1.5",
"raw-text-loader": "0.1.1",
"replace-hash-in-file-webpack-plugin": "1.0.8",
"scriptjs": "2.5.9",
"style-loader": "0.23.1",
"unused-files-webpack-plugin": "^3.4.0",
"url-loader": "1.1.2",
"webpack": "^5.38.1",
"webpack-cli": "^4.7.2"
},
Here is the webpack file
const webpack = require('webpack');
const path = require('path');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ReplaceHashInFileWebpackPlugin = require('replace-hash-in-file-webpack-plugin');
const brandingDefinePlugin = require('./configs/plugins');
const env = process.env.NODE_ENV;
const config = {
entry: [
"./src/main/webapp/app/scripts/index.js"
],
output: {
path: path.resolve(__dirname, "build"),
filename: env !== "development" ? '[name]-[hash].js' : '[name]-dev.js'
},
module: {
rules: [
{
test:/\.m?js$/,
loader: "babel-loader",
options:{
exclude: /(node_modules|bower_components)/,
compact: false
}
//query: {compact: false}
},
{
test: /\.dust$/,
use: [{
loader: "dust-loader",
options: {
rootDir: './src/main/webapp/app/scripts/templates'
}
}]
},
{
test: require.resolve('highcharts'),
use: [{
loader: 'expose-loader',
options: 'Highcharts'
}]
},
{
test: require.resolve('underscore'),
use: [{
loader: 'expose-loader',
options: '_'
}]
},
{
test: path.resolve(__dirname, './src/main/webapp/app/scripts/app'),
use: [{
loader: 'expose-loader',
options: 'app'
}]
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
//importLoaders: 1,
sourceMap: env === 'development',
url: false,
//context: '../',
}
},
]
},
{
test: /\.less$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'less-loader']
},
{
test: /\.(jpg|jpeg|gif|png|svg)$/,
use: [{
loader: 'file-loader?name=../../images/[name].[ext]'
}]
},
{
test: /\.(woff|woff2|eot|ttf|svg)$/,
use: [{
loader: 'url-loader?name=fonts/[name].[ext]'
}]
//loader: 'url-loader?name=fonts/[name].[ext]'
},
]
},
stats: {
colors: true,
errorDetails: true
},
externals: {
'jquery': 'jQuery'
},
resolve: {
extensions: ['.js', '.jsx'],
modules: ['node_modules', 'bower_components'],
descriptionFiles: ['package.json', 'bower.json'],
alias: {
'jquery-i18n': path.resolve(__dirname, "./src/main/webapp/app/scripts/vendor/jquery.i18n.properties-1.0.9"),
'jquery-ui': path.resolve(__dirname, './src/main/webapp/app/scripts/vendor/jquery-ui'),
"bootstrap-datetimepicker": path.resolve(__dirname, "./src/main/webapp/app/scripts/vendor/bootstrap-datetimepicker.min"),
mousewheel: path.resolve(__dirname, './src/main/webapp/app/scripts/vendor/jquery.mousewheel'),
atmosphere: path.resolve(__dirname, './src/main/webapp/app/bower_components/jquery.atmosphere/jquery.atmosphere'),
x2js: path.resolve(__dirname, './src/main/webapp/app/scripts/vendor/xml2json.min'),
helpers: path.resolve(__dirname, './src/main/webapp/app/scripts/helpers'),
jscrollpane: path.resolve(__dirname, './src/main/webapp/app/scripts/vendor/jquery.jscrollpane'),
jqgridlocale: path.resolve(__dirname, './src/main/webapp/app/scripts/vendor/grid.locale-en'),
'jqgrid': path.resolve(__dirname, './src/main/webapp/app/scripts/vendor/jquery.jqGrid.js'),
idleTimer: path.resolve(__dirname, './src/main/webapp/app/scripts/vendor/idle-timer.min'),
'jquery-tag-it': path.resolve(__dirname,'./src/main/webapp/app/bower_components/jquery-tagit/js/tag-it'),
jsonview: path.resolve(__dirname, './node_modules/jquery-jsonview/dist/jquery.jsonview'),
gridster: path.resolve(__dirname, './src/main/webapp/app/bower_components/gridster/src/jquery.gridster.js'),
'jquery-ui-multiselect-widget': path.resolve(__dirname, './src/main/webapp/app/scripts/vendor/jquery.multiselect'),
'file-saver': path.resolve(__dirname, './node_modules/file-saver/FileSaver.min'),
jqueryTimeDuration: path.resolve(__dirname, './src/main/webapp/app/bower_components/jquery-time-duration-picker/src/jquery-time-duration-picker'),
'jQuery-contextMenu': path.resolve(__dirname, './src/main/webapp/app/bower_components/jQuery-contextMenu/dist/jquery.contextMenu.js'),
applicationTemplates: path.resolve(__dirname, './src/main/webapp/app/scripts/applicationTemplates'),
dust: path.resolve(__dirname, './node_modules/dustjs-linkedin/lib/dust'),
'dust.core': 'dustjs-linkedin',
'dust.parse': path.resolve(__dirname, './node_modules/dustjs-linkedin/lib/parser'),
dustCompiler: path.resolve(__dirname, './node_modules/dustjs-linkedin/lib/compiler'),
dustHelpers: 'dustjs-helpers',
app: path.resolve(__dirname, './src/main/webapp/app/scripts/app'),
routes: path.resolve(__dirname, './src/main/webapp/app/scripts/routes'),
collections: path.resolve(__dirname, './src/main/webapp/app/scripts/collections'),
views: path.resolve(__dirname, './src/main/webapp/app/scripts/views'),
models: path.resolve(__dirname, './src/main/webapp/app/scripts/models'),
schemas: path.resolve(__dirname, './src/main/webapp/app/scripts/schemas'),
templates: path.resolve(__dirname, './src/main/webapp/app/scripts/templates'),
controllers: path.resolve(__dirname, './src/main/webapp/app/scripts/controllers'),
'custom-form-elements': path.resolve(__dirname, './src/main/webapp/app/scripts/helpers/custom-form-elements'),
js: path.resolve(__dirname, './src/main/webapp/app/js'),
bubble_chat: path.resolve(__dirname, './src/main/webapp/app/scripts/helpers/bubble_chat'),
leaflet: path.resolve(__dirname, './src/main/webapp/app/bower_components/leaflet/leaflet'),
MarkerCluster: path.resolve(__dirname, './src/main/webapp/app/scripts/vendor/MasterCluster-src'),
jstree: path.resolve(__dirname, './node_modules/jstree/dist/jstree.min'),
geosearch: path.resolve(__dirname, './src/main/webapp/app/bower_components/L.GeoSearch/src/js/l.control.geosearch'),
openstreetmap: path.resolve(__dirname, './src/main/webapp/app/bower_components/L.GeoSearch/src/js/l.geosearch.provider.openstreetmap'),
googleProvider: path.resolve(__dirname, './src/main/webapp/app/bower_components/L.GeoSearch/src/js/l.geosearch.provider.google'),
'intl-tel-input': path.resolve(__dirname, './node_modules/intl-tel-input/build/js/intlTelInput-jquery.min'),
adapter: path.resolve(__dirname, './src/main/webapp/app/scripts/adapter'),
next: path.resolve(__dirname, './src/main/webapp/app/scripts/next'),
spin: path.resolve(__dirname, './src/main/webapp/app/bower_components/spin/'),
'fileSaver': path.resolve(__dirname, './node_modules/file-saver/FileSaver'),
'vApiClient': path.resolve(__dirname, './src/main/webapp/app/api/vApiClient'),
vendorUtils: path.resolve(__dirname, './src/main/webapp/app/scripts/vendor/utils')
}
},
resolveLoader: {
alias: { "text": "raw-text-loader" }
},
mode: env,
plugins: [
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
options: {
context: __dirname
}
}),
new webpack.ProvidePlugin({
_: 'underscore',
dust: 'dustjs-linkedin',
jQuery: 'jquery',
$: 'jquery',
_ld:'lodash'
}),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
}),
new MiniCssExtractPlugin({
filename: env !== "development" ? 'styles/css/main-[hash].css' : 'styles/css/main-dev.css'
}),
new ReplaceHashInFileWebpackPlugin([{
dir: 'build',
files: ['index.jsp'],
rules: [{
search: /\/main/ig,
replace: env !== "development" ? '/main-[hash]' : '/main-dev'
}]
}])
]
}
if (process.env.npm_config_branding === 'riverbed') {
console.log('******************** Branding : Riverbed *********************',
process.env.npm_config_branding);
console.log(JSON.stringify(brandingDefinePlugin));
config.plugins.push(brandingDefinePlugin.riverbed.oem);
} else {
console.log('******************** Branding : Versa *********************', process.env.npm_config_branding);
console.log(JSON.stringify(brandingDefinePlugin));
config.plugins.push(brandingDefinePlugin.versa.oem);
}
if (!process.env.NO_COPY) {
config.plugins.push(new CopyWebpackPlugin({patterns:[
{
from: 'src/main/webapp/app/mock/json/*.json',
to: 'mock/json',
toType: 'dir',
},
{
from: 'src/main/webapp/app/*.jsp',
toType: 'file',
toType: 'dir',
}, {
from: 'src/main/webapp/app/jsp',
to: 'jsp/',
},
{
from: 'src/main/webapp/app/scripts/vendor',
to: 'vendor/',
},
{
from: 'src/main/webapp/app/scripts/vendor/codemirror',
to: 'vendor/codemirror',
},
{
from: 'src/main/webapp/app/scripts/vendor/diff_match_patch',
to: 'vendor/diff_match_patch',
}, {
from: 'src/main/webapp/app/scripts/vendor/next',
to: 'vendor/next',
}, {
from: 'src/main/webapp/app/styles/',
to: 'styles/'
}, {
from: 'src/main/webapp/app/bower_components/',
to: 'bower_components/'
}, {
from: 'src/main/webapp/app/footerName.txt'
}, {
from: 'src/main/webapp/app/favicon.png'
}, {
from: 'src/main/webapp/app/favicon.ico'
}, {
from: 'src/main/webapp/app/404.html'
}, {
from: 'src/main/webapp/app/logoName.txt'
}, {
from: 'src/main/webapp/app/robots.txt'
}, {
from: 'src/main/webapp/app/favicon_original.png'
}, {
from: 'src/main/webapp/app/images/',
to: 'images/'
}, {
from: 'src/main/webapp/app/styles/img/',
to: 'styles/img'
}, {
from: 'node_modules/noVNC',
to: 'vendor/noVNC',
}, {
from: 'src/main/webapp/app/scripts/novnc',
to: 'novnc',
},
{
from: 'node_modules/bootstrap/dist/css',
to: 'styles/css/bootstrap/',
},
{
from: 'node_modules/bootstrap/dist/js',
to: 'bower_components/bootstrap/',
},
{
from: 'node_modules/jquery/dist',
to: 'bower_components/jquery/dist',
},
{
from: 'src/main/webapp/app/scripts/jspScriptHandlers',
to:"jspScriptHandlers"
}]}
))
}
module.exports = config;
Out put of running webpack
ERROR] [webpack.Progress] 10% building
[ERROR] [webpack.Progress] 10% building 0/1 entries 0/0 dependencies 0/0 modules
[ERROR] (node:27426) ExperimentalWarning: queueMicrotask() is experimental.
[ERROR] (node:27426) [DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING] DeprecationWarning: Using a string as loader options is deprecated (ruleSet[1].rules[2].use[0].options)
[ERROR] [webpack.Progress] 10% building import loader ./node_modules/babel-loader/lib/index.js
[ERROR] [webpack.Progress] 10% building 0/1 entries 1/1 dependencies 0/1 modules
Had the same problem and, surprisingly, I've found the resolve.alias option to be the culprit. Removing one particular item from there caused the build to succeed.

How to use npm file in webpack version 4.42.0

I started the use the web pack version 4.42.0, I can build the web-pack and able to run it. But whenever I include below code. I get an error, Please would anyone can help how to use npm fs in web-pack
Index.js
var fs = require('fs');
console.log(fs.readFileSync());
and my webpack-config.js
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
module: {
rules: [
{
test: /\.html$/i,
loader: 'html-loader',
options: { minimize: true }
},
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['#babel/preset-env']
}
}
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: 'file-loader',
},
],
},
{
test: /\.node$/,
use: 'node-loader'
}
],
},
plugins: [new HtmlWebpackPlugin({
template: "./src/index.html",
filename: "./index.html"
},
)],
mode: 'development',
node: { fs: 'empty' },
target: "node"
};
I am facing the error
Uncaught TypeError: fs.readFileSync is not a function
After removing node and target from webpack-config.js
ERROR in ./src/index.js
Module not found: Error: Can't resolve 'fs' in '/Users/nagaraj/gowork/src/github.com/webpack_tutor/src'
# ./src/index.js 1:9-22
package.json
"devDependencies": {
"#babel/core": "^7.8.7",
"#babel/preset-env": "^7.8.7",
"babel-loader": "^8.0.6",
"file-loader": "^5.1.0",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"node-loader": "^0.6.0",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11"
},
"dependencies": {
"fs": "0.0.1-security",
"lodash-webpack-plugin": "^0.11.5",
"webpack-dev-server": "^3.10.3"
}

webpack is failing while trying to compile in production mode

I've been using React 16.x.x and Jqwidgets 6.2.0 and React Boilerplate 3.7.0. My whole project was mounted over the React Boilerplate scaffold with its own configuration of webpack. I set jqwigets-scripts as a npm dependency and I tried excluding node_modules but including jqwidgets-scripts/jqwidgets-react through a regular expression as I read in some github. This is my current webpack.base.babel.js file:
...
module: {
rules: [
{
test: /\.js$/, // Transform all .js files required somewhere with Babel
exclude: /node_modules\/(?!(jqwidgets-scripts\/jqwidgets-react)\/).*/,
use: {
loader: 'babel-loader',
options: options.babelQuery,
},
},
...
With this configuration webpack compiles with no warnings and no errors like a charm, that is to say npm start. The big deal comes out to stage if I say npm run-script build, if so it complains with this:
Hash: 7b0feef0f8bbac0c9421
Version: webpack 4.27.1
Time: 41489ms
Built at: 2019-01-24 08:13:05
251 assets
Entrypoint main = runtime~main.43b100be02c6a9dbfc5a.js vendor.4d1e1f30cd3a7c98cfd8.chunk.js main.5ce13ffd96704eeb6b0d.chunk.js
ERROR in ./node_modules/jqwidgets-scripts/jqwidgets-react/react_jqxgrid.js 1216:12
Module parse failed: Unexpected token (1216:12)
You may need an appropriate loader to handle this file type.
| render() {
| return (
> <div id={this.state.id}>{this.props.value}{this.props.children}</div>
| )
| };
# ./app/modules/MyModule_1/index.js 43:0-70 954:37-44
# ./app/modules/MyModule_2/Loadable.js
# ./app/modules/MyModule_3/_nav.js
# ./app/modules/MyModule_4/index.js
# ./app/modules/MyModule_5/Loadable.js
# ./app/containers/MainLayout/_nav.js
# ./app/containers/MainLayout/index.js
# ./app/containers/MainLayout/Loadable.js
# ./app/containers/App/index.js
# ./app/app.js
# multi ./node_modules/react-app-polyfill/ie11.js ./app/app.js
I tried changing my webpack configuration as recommended in the official jqwidgets page (https://www.jqwidgets.com/community/topic/webpack-module-parse-failed/) like this:
module: {
rules: [
{
test: /\.js$/,
exclude: '/node_modules',
include: '/node_modules/jqwidgets-scripts/jqwidgets-react',
use: {
loader: 'babel-loader',
options: options.babelQuery
}
},
Then the complain is this while running npm start:
webpack built be60767d46a99fe48e6b in 1353ms
✖ 「wdm」:
ERROR in ./app/app.js 80:4
Module parse failed: Unexpected token (80:4)
You may need an appropriate loader to handle this file type.
| const render = messages => {
| ReactDOM.render(
> <AppContainer>
| <Provider store={store}>
| <LanguageProvider messages={messages}>
# multi ./node_modules/react-app-polyfill/ie11.js webpack-hot-middleware/client?reload=true ./app/app.js main[2]
Also, this is my babel.config.js
module.exports = {
presets: [
[
'#babel/preset-env',
{
modules: false,
},
],
'#babel/preset-react',
],
plugins: [
'styled-components',
'#babel/plugin-proposal-export-namespace-from',
'#babel/plugin-proposal-class-properties',
'#babel/plugin-syntax-dynamic-import',
],
env: {
production: {
only: ['app'],
plugins: [
'lodash',
'transform-react-remove-prop-types',
'#babel/plugin-transform-react-inline-elements',
'#babel/plugin-transform-react-constant-elements',
],
},
test: {
plugins: [
'#babel/plugin-transform-modules-commonjs',
'dynamic-import-node',
],
},
},
};
My package.json:
{
"name": "react-boilerplate",
"version": "3.7.0",
"description": "A highly scalable, offline-first foundation with the best DX and a focus on performance and best practices",
"repository": {
"type": "git",
"url": "git://github.com/react-boilerplate/react-boilerplate.git"
},
"engines": {
"npm": ">=5",
"node": ">=8.10.0"
},
"author": "Max Stoiber",
"license": "MIT",
"scripts": {
"analyze:clean": "rimraf stats.json",
"preanalyze": "npm run analyze:clean",
"analyze": "node ./internals/scripts/analyze.js",
"extract-intl": "node ./internals/scripts/extract-intl.js",
"npmcheckversion": "node ./internals/scripts/npmcheckversion.js",
"preinstall": "npm run npmcheckversion",
"prebuild": "npm run build:clean",
"build": "cross-env NODE_ENV=production webpack --config internals/webpack/webpack.prod.babel.js --color -p --progress --hide-modules --display-optimization-bailout",
"build:clean": "rimraf ./build",
"start": "cross-env NODE_ENV=development env-cmd .env node server",
"start:tunnel": "cross-env NODE_ENV=development ENABLE_TUNNEL=true node server",
"start:production": "npm run test && npm run build && npm run start:prod",
"start:prod": "cross-env NODE_ENV=production node server",
"presetup": "npm i chalk shelljs",
"setup": "node ./internals/scripts/setup.js",
"clean": "shjs ./internals/scripts/clean.js",
"clean:all": "npm run analyze:clean && npm run test:clean && npm run build:clean",
"generate": "plop --plopfile internals/generators/index.js",
"lint": "npm run lint:js",
"lint:css": "stylelint './app/**/*.js'",
"lint:eslint": "eslint --ignore-path .gitignore --ignore-pattern internals/scripts",
"lint:eslint:fix": "eslint --ignore-path .gitignore --ignore-pattern internals/scripts --fix",
"lint:js": "npm run lint:eslint -- . ",
"lint:staged": "lint-staged",
"pretest": "npm run test:clean && npm run lint",
"test:clean": "rimraf ./coverage",
"test": "cross-env NODE_ENV=test jest --coverage",
"test:watch": "cross-env NODE_ENV=test jest --watchAll",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"prettify": "prettier --write"
},
"lint-staged": {
"*.js": [
"npm run lint:eslint:fix",
"git add --force"
],
"*.json": [
"prettier --write",
"git add --force"
]
},
"pre-commit": "lint:staged",
"resolutions": {
"babel-core": "7.0.0-bridge.0"
},
"dependencies": {
"#coreui/coreui": "^2.1.4",
"#coreui/coreui-plugin-chartjs-custom-tooltips": "^1.2.0",
"#coreui/icons": "^0.3.0",
"#coreui/react": "^2.1.1",
"ajv": "^6.6.1",
"babel-polyfill": "^6.26.0",
"block-ui": "^2.70.1",
"bootstrap": "^4.1.3",
"chalk": "^2.4.1",
"chart.js": "^2.7.3",
"classnames": "^2.2.6",
"compression": "^1.7.3",
"connected-react-router": "^4.5.0",
"core-js": "^2.6.0",
"env-cmd": "^8.0.2",
"exports-loader": "^0.7.0",
"flag-icon-css": "^3.2.1",
"font-awesome": "^4.7.0",
"fontfaceobserver": "2.0.13",
"history": "^4.7.2",
"hoist-non-react-statics": "3.0.1",
"immutable": "^3.8.2",
"intl": "^1.2.5",
"invariant": "^2.2.4",
"ip": "^1.1.5",
"is-url-external": "^1.0.3",
"isnumeric": "^0.3.3",
"jquery": "^3.3.1",
"jqwidgets-scripts": "^6.2.0",
"loadable-components": "^2.2.3",
"lodash": "^4.17.11",
"minimist": "1.2.0",
"moment": "^2.22.2",
"numeral": "^2.0.6",
"prop-types": "^15.6.2",
"react": "^16.6.3",
"react-chartjs-2": "^2.7.4",
"react-dom": "^16.6.3",
"react-helmet": "^5.2.0",
"react-hot-loader": "^4.6.3",
"react-intl": "^2.7.2",
"react-loadable": "^5.5.0",
"react-redux": "^5.1.1",
"react-router-dom": "^4.3.1",
"react-sizeme": "^2.5.2",
"reactstrap": "^6.5.0",
"redux": "^4.0.1",
"redux-immutable": "^4.0.0",
"redux-saga": "^0.16.2",
"reselect": "4.0.0",
"resize-sensor": "0.0.6",
"sanitize.css": "4.1.0",
"simple-line-icons": "^2.4.1",
"styled-components": "^4.1.2",
"warning": "^4.0.2"
},
"devDependencies": {
"#babel/cli": "7.1.2",
"#babel/core": "7.1.2",
"#babel/plugin-proposal-class-properties": "7.1.0",
"#babel/plugin-proposal-export-namespace-from": "^7.2.0",
"#babel/plugin-syntax-dynamic-import": "7.0.0",
"#babel/plugin-transform-modules-commonjs": "7.1.0",
"#babel/plugin-transform-react-constant-elements": "7.0.0",
"#babel/plugin-transform-react-inline-elements": "7.0.0",
"#babel/polyfill": "^7.0.0",
"#babel/preset-env": "7.1.0",
"#babel/preset-react": "7.0.0",
"#babel/register": "7.0.0",
"add-asset-html-webpack-plugin": "3.1.1",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.1",
"babel-loader": "8.0.4",
"babel-plugin-dynamic-import-node": "2.2.0",
"babel-plugin-lodash": "3.3.4",
"babel-plugin-react-intl": "3.0.1",
"babel-plugin-react-transform": "3.0.0",
"babel-plugin-styled-components": "1.8.0",
"babel-plugin-transform-react-remove-prop-types": "0.4.19",
"circular-dependency-plugin": "5.0.2",
"compare-versions": "3.4.0",
"compression-webpack-plugin": "2.0.0",
"copy-webpack-plugin": "^4.6.0",
"coveralls": "3.0.2",
"cross-env": "^5.2.0",
"css-loader": "1.0.0",
"enzyme": "3.7.0",
"enzyme-adapter-react-16": "1.6.0",
"enzyme-to-json": "3.3.4",
"eslint": "5.7.0",
"eslint-config-airbnb": "17.1.0",
"eslint-config-airbnb-base": "13.1.0",
"eslint-config-prettier": "3.1.0",
"eslint-import-resolver-webpack": "0.10.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "6.1.2",
"eslint-plugin-prettier": "3.0.0",
"eslint-plugin-react": "7.11.1",
"eslint-plugin-redux-saga": "0.9.0",
"express": "^4.16.4",
"file-loader": "2.0.0",
"html-loader": "0.5.5",
"html-webpack-plugin": "3.2.0",
"http-proxy-middleware": "^0.19.1",
"image-webpack-loader": "^4.6.0",
"imports-loader": "0.8.0",
"jest-cli": "23.6.0",
"jest-styled-components": "6.2.2",
"lint-staged": "7.3.0",
"ngrok": "3.1.0",
"node-plop": "0.16.0",
"node-sass": "^4.11.0",
"null-loader": "0.1.1",
"offline-plugin": "5.0.5",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"plop": "2.1.0",
"pre-commit": "1.2.2",
"prettier": "1.14.3",
"react-app-polyfill": "0.1.3",
"react-test-renderer": "16.6.0",
"rimraf": "2.6.2",
"sass-loader": "^7.1.0",
"shelljs": "^0.8.3",
"style-loader": "0.23.1",
"stylelint": "9.6.0",
"stylelint-config-recommended": "2.1.0",
"stylelint-config-styled-components": "0.1.1",
"stylelint-processor-styled-components": "1.5.0",
"svg-url-loader": "2.3.2",
"terser-webpack-plugin": "1.1.0",
"uglifyjs-webpack-plugin": "^2.0.1",
"url-loader": "1.1.2",
"webpack": "^4.27.1",
"webpack-cli": "^3.1.2",
"webpack-dev-middleware": "3.4.0",
"webpack-hot-middleware": "2.24.3 ",
"webpack-pwa-manifest": "3.7.1",
"whatwg-fetch": "3.0.0"
}
}
My webpack.prod.babel.js:
// Important modules this config uses
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackPwaManifest = require('webpack-pwa-manifest');
const OfflinePlugin = require('offline-plugin');
const { HashedModuleIdsPlugin } = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
module.exports = require('./webpack.base.babel')({
mode: 'production',
// In production, we skip all hot-reloading stuff
entry: [
require.resolve('react-app-polyfill/ie11'),
path.join(process.cwd(), 'app/app.js'),
],
// Utilize long-term caching by adding content hashes (not compilation hashes) to compiled assets
output: {
filename: '[name].[chunkhash].js',
chunkFilename: '[name].[chunkhash].chunk.js',
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
warnings: false,
compress: {
comparisons: false,
},
parse: {},
mangle: true,
output: {
comments: false,
ascii_only: true,
},
},
parallel: true,
cache: true,
sourceMap: true,
}),
],
nodeEnv: 'production',
sideEffects: true,
concatenateModules: true,
splitChunks: {
chunks: 'all',
minSize: 30000,
minChunks: 1,
maxAsyncRequests: 10,
maxInitialRequests: 3,
name: true,
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all',
},
main: {
chunks: 'all',
minChunks: 2,
reuseExistingChunk: true,
enforce: true,
},
},
},
runtimeChunk: true,
},
plugins: [
// Minify and optimize the index.html
new HtmlWebpackPlugin({
template: 'app/index.html',
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
inject: true,
}),
// Put it in the end to capture all the HtmlWebpackPlugin's
// assets manipulations and do leak its manipulations to HtmlWebpackPlugin
new OfflinePlugin({
relativePaths: false,
publicPath: '/',
appShell: '/',
// No need to cache .htaccess. See http://mxs.is/googmp,
// this is applied before any match in `caches` section
excludes: ['.htaccess'],
caches: {
main: [':rest:'],
// All chunks marked as `additional`, loaded after main section
// and do not prevent SW to install. Change to `optional` if
// do not want them to be preloaded at all (cached only when first loaded)
additional: ['*.chunk.js'],
},
// Removes warning for about `additional` section usage
safeToUseOptionalCaches: true,
}),
new CompressionPlugin({
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8,
}),
new WebpackPwaManifest({
name: 'React Boilerplate',
short_name: 'React BP',
description: 'My React Boilerplate-based project!',
background_color: '#fafafa',
theme_color: '#b1624d',
inject: true,
ios: true,
icons: [
{
src: path.resolve('app/images/icon-512x512.png'),
sizes: [72, 96, 128, 144, 192, 384, 512],
},
{
src: path.resolve('app/images/icon-512x512.png'),
sizes: [120, 152, 167, 180],
ios: true,
},
],
}),
new HashedModuleIdsPlugin({
hashFunction: 'sha256',
hashDigest: 'hex',
hashDigestLength: 20,
}),
],
performance: {
assetFilter: assetFilename =>
!/(\.map$)|(^(main\.|favicon\.))/.test(assetFilename),
},
});
My webpack.dev.babel.js:
/**
* DEVELOPMENT WEBPACK CONFIGURATION
*/
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
module.exports = require('./webpack.base.babel')({
mode: 'development',
// Add hot reloading in development
entry: [
require.resolve('react-app-polyfill/ie11'),
'webpack-hot-middleware/client?reload=true',
path.join(process.cwd(), 'app/app.js'), // Start with js/app.js
],
// Don't use hashes in dev mode for better performance
output: {
filename: '[name].js',
chunkFilename: '[name].chunk.js',
},
optimization: {
splitChunks: {
chunks: 'all',
},
},
// Add development plugins
plugins: [
new webpack.HotModuleReplacementPlugin(), // Tell webpack we want hot reloading
new HtmlWebpackPlugin({
inject: true, // Inject all files that are generated by webpack, e.g. bundle.js
template: 'app/index.html',
}),
new CircularDependencyPlugin({
exclude: /a\.js|node_modules/, // exclude node_modules
failOnError: false, // show a warning when there is a circular dependency
}),
],
// Emit a source map for easier debugging
// See https://webpack.js.org/configuration/devtool/#devtool
devtool: 'eval-source-map',
performance: {
hints: false,
},
});
And finally my webpack.base.babel.js:
/**
* COMMON WEBPACK CONFIGURATION
*/
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const config = require('../../server/config');
// Remove this line once the following warning goes away (it was meant for webpack loader authors not users):
// 'DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic,
// see https://github.com/webpack/loader-utils/issues/56 parseQuery() will be replaced with getOptions()
// in the next major version of loader-utils.'
process.noDeprecation = true;
module.exports = options => ({
mode: options.mode,
entry: options.entry,
output: Object.assign(
{
// Compile into js/build.js
path: path.resolve(process.cwd(), 'build'),
publicPath: '/',
},
options.output,
), // Merge with env dependent settings
optimization: options.optimization,
module: {
rules: [
{
test: /\.js$|\.jsx$/, // Transform all .js files required somewhere with Babel
exclude: /node_modules\/(?!(jqwidgets-scripts\/jqwidgets-react)\/).*/,
use: {
loader: 'babel-loader',
options: options.babelQuery,
},
},
// {
// test: /\.js$|\.jsx$/,
// exclude: '/node_modules',
// include: '/jqwidgets-scripts/jqwidgets-react',
// use: {
// loader: 'babel-loader',
// options: options.babelQuery
// }
// },
{
// Preprocess our own .css files
// This is the place to add your own loaders (e.g. sass/less etc.)
// for a list of loaders, see https://webpack.js.org/loaders/#styling
test: /\.scss$/,
exclude: /node_modules/,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
// Preprocess 3rd party .css files located in node_modules
test: /\.css$/,
include: /node_modules/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(eot|otf|ttf|woff|woff2)$/,
use: 'file-loader',
},
{
test: /\.svg$/,
use: [
{
loader: 'svg-url-loader',
options: {
// Inline files smaller than 10 kB
limit: 10 * 1024,
noquotes: true,
},
},
],
},
{
test: /\.(jpg|png|gif)$/,
use: [
{
loader: 'url-loader',
options: {
// Inline files smaller than 10 kB
limit: 10 * 1024,
},
},
{
loader: 'image-webpack-loader',
options: {
mozjpeg: {
enabled: false,
// NOTE: mozjpeg is disabled as it causes errors in some Linux environments
// Try enabling it in your environment by switching the config to:
// enabled: true,
// progressive: true,
},
gifsicle: {
interlaced: false,
},
optipng: {
optimizationLevel: 7,
},
pngquant: {
quality: '65-90',
speed: 4,
},
},
},
],
},
{
test: /\.html$/,
use: 'html-loader',
},
{
test: /\.(mp4|webm)$/,
use: {
loader: 'url-loader',
options: {
limit: 10000,
},
},
},
],
},
plugins: options.plugins.concat([
// Always expose NODE_ENV to webpack, in order to use `process.env.NODE_ENV`
// inside your code for any environment checks; Terser will automatically
// drop any unreachable code.
/* new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
}), */
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(config.env),
HOST: JSON.stringify(config.server_host),
PORT: JSON.stringify(config.server_port)
},
}),
new webpack.NamedModulesPlugin(),
new CopyWebpackPlugin([{ from: 'static' }]),
]),
resolve: {
modules: ['node_modules', 'app'],
extensions: ['.js', '.jsx', '.react.js'],
mainFields: ['browser', 'jsnext:main', 'main'],
alias: {
moment$: 'moment/moment.js',
},
},
devtool: options.devtool,
target: 'web', // Make web variables accessible to webpack, e.g. window
performance: options.performance || {},
});
My question is, how to configure webpack in order to work properly in production mode?

brunch.io conventions.ignored does not respect node_modules

I'm building an app that has multiple entry points. It's a plugin/sideloading react architecture.
I have a base react app compiling into app.js and vendor.js just fine. The issue originates with the secondary project, the theme, being bundled with some of the same dependencies. Most notably react and react-dom. I would like to be able to use conventions.ignored to instruct brunch to ignore specific node_modules and their dependencies. Regardless of the regex I put in conventions.ignored I still get react and react-dom in the theme_vendor.js bundle. See config below:
const {theme_name} = require('./package.json');
module.exports = {
sourceMaps: 'inline',
files: {
javascripts: {
joinTo: {
"theme.js": [
/^theme/,
],
"theme_vendor.js": [
/^(?!theme)/,
],
}
},
stylesheets: {
joinTo: {
'theme.css': ["theme/config/styles/index.scss"],
'theme_ie11.css': ["theme/config/styles/ie.scss"],
}
}
},
conventions: {
ignored: [
/\/_/,
"node_modules\/react",
"node_modules\/react-dom",
],
},
plugins: {
babel: {
presets: ['es2015', 'stage-0', 'react'],
plugins: [
['transform-runtime', {
polyfill: false,
regenerator: true
}]
],
},
sass: {
options: {
includePaths: [],
precision: 15
},
mode: 'native',
sourceMapEmbed: true,
debug: 'comments'
},
copycat: {
"fonts/slick-carousel": ["node_modules/slick-carousel/slick/fonts"],
"img/slick-carousel": ["node_modules/slick-carousel/slick/ajax-loader.gif"],
"": ["theme/theme_header.tmpl", "theme/theme_body.tmpl", "theme/theme_footer.tmpl"],
}
},
modules: {
nameCleaner: path => path.replace('', theme_name + '/')
},
notifications: false,
hot: false,
paths: {
public: '../',
watched: [
'theme',
'initialize.js',
]
},
overrides: {
production: {
optimize: true,
sourceMaps: false,
plugins: {
autoReload: {
enabled: false
}
},
paths: {
// public: "dist/"
}
}
}
};
The only way I have been able to achieve anything close is to use a negation in the joinTo. See Below:
javascripts: {
joinTo: {
"theme.js": [
/^theme/,
],
"theme_vendor.js": [
/^(?!theme|node_modules\/react|node_modules\/react-dom)/,
],
}
},
Other info:
"dependencies": {
"react-click-outside": "^2.2.0",
"react-image-gallery": "^0.7.15",
"react-slick": "^0.14.7",
"slick-carousel": "^1.6.0"
},
"devDependencies": {
"auto-reload-brunch": "^2",
"babel-brunch": "~6.0.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.0",
"babel-preset-react": "~6.22",
"babel-preset-stage-0": "^6.22.0",
"brunch": "^2",
"clean-css-brunch": "^2",
"copycat-brunch": "^1.1.0",
"hmr-brunch": "^0.1",
"redux-devtools": "^3.3.2",
"redux-devtools-dock-monitor": "^1.1.1",
"redux-devtools-log-monitor": "^1.2.0",
"sass-brunch": "^2.10.4",
"uglify-js-brunch": "^2",
"isomorphic-fetch": "^2.2.1",
"react": "^15.4",
"react-addons-css-transition-group": "^15.4.2",
"react-dom": "^15.4",
"react-redux": "~4.3.0",
"react-router": "^3.0.2",
"react-router-redux": "^4.0.8",
"redux": "~3.2.1",
"redux-form": "^6.6.2",
"redux-logger": "^3.0.0",
"redux-saga": "^0.14.3"
}
I think you need to do this:
conventions: {
vendor: /(^bower_components|node_modules(?!\/react)|vendor)\//
}
See also the docs.
This regex will not match the two react node modules and therefore will not be included in your file.

Resources