Issue with npm start and compiling in react - reactjs

so i have been assigned to maintain a react website. i am facing some problem with running the project.. npm start takes approx 4-5mins and likewise every changes saved takes upto 2-3mins(which is toooooo long). I am unable to figure out where is the issue. Maybe in webpack configuration or something else. Code details are listed bellow:
webpack.config.js
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var webpack = require('webpack');
module.exports = {
entry: './src/index.jsx',
output: {
path: path.resolve('dist'),
filename: 'bundle.js',
},
resolve: {
extensions: ['.js', '.jsx', '.css'],
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-3']
}
},
{ test: /\.css$/, loader: "style-loader!css-loader" },
{
test: /\.less$/,
loader: 'style-loader!css-loader!less-loader'// compiles Less to CSS
},
{
test: /\.(png|jpg|)$/,
loader: 'url-loader?limit=200000'
}
]
},
plugins: [new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'index.html',
inject: 'body'
}), new CopyWebpackPlugin([ { from: 'src/assets', to: 'assets' } ]),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
mangle: true,
// compress: {
// warnings: false, // Suppress uglification warnings
// pure_getters: true,
// unsafe: true,
// unsafe_comps: true,
// screw_ie8: true,
// conditionals: true,
// unused: true,
// comparisons: true,
// sequences: true,
// dead_code: true,
// evaluate: true,
// if_return: true,
// join_vars: true
// },
output: {
comments: false,
},
exclude: [/\.min\.js$/gi] // skip pre-minified libs
}),
],
devServer: {
historyApiFallback: true
},
externals: {
// global app config object
config: JSON.stringify({
// apiUrl: 'http://0.0.0.0:8102',
siteUrl: 'http://localhost:ls3003',
apiUrl: 'https://api.xyz.com',
// siteUrl: 'https://dashboard.mltrons.com',
})
}
}
Package.json:
"name": "react-redux-registration-login-example",
"version": "1.0.0",
"repository": {
"type": "git",
"url": "https://github.com/cornflourblue/react-redux-registration-login-example.git"
},
"license": "MIT",
"scripts": {
"start": "webpack-dev-server --host 0.0.0.0 --port 3000 --disableHostCheck",
"build": "webpack"
},
"dependencies": {
"#amcharts/amcharts4": "^4.2.3",
"#data-ui/histogram": "0.0.75",
"#material-ui/core": "^3.9.0",
"#material-ui/icons": "^3.0.2",
"#projectstorm/react-diagrams": "^6.0.1-beta.5",
"chart.js": "^2.7.3",
"chartjs-plugin-zoom": "^0.6.6",
"classnames": "^2.2.6",
"css-loader": "^2.1.0",
"deni-react-treeview": "^0.2.15",
"events": "^3.0.0",
"formik": "^1.4.1",
"history": "^4.6.3",
"jquery": "^3.3.1",
"material-ui-popup-state": "^1.0.2",
"moment": "^2.23.0",
"pusher-js": "^4.3.1",
"rc-steps": "^3.3.1",
"react": "^16.0.0",
"react-addons-css-transition-group": "^15.6.2",
"react-chartjs-2": "^2.7.4",
"react-circular-progressbar": "^1.0.0",
"react-craft-ai-decision-tree": "0.0.26",
"react-datetime-picker": "^2.1.1",
"react-dom": "^16.0.0",
"react-dropzone": "^8.0.3",
"react-facebook-login": "^4.1.1",
"react-ga": "^2.5.7",
"react-google-login": "^4.0.1",
"react-heatmap-grid": "^0.7.3",
"react-highlight": "^0.12.0",
"react-joyride": "^2.0.5",
"react-linkedin-login-oauth2": "^1.0.6",
"react-paginate": "^6.2.1",
"react-redux": "^5.0.5",
"react-router-dom": "^4.1.2",
"react-table": "^6.8.6",
"recharts": "^1.8.5",
"redux": "^3.7.2",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.2.0",
"style-loader": "^0.23.1",
"web-wechat-login": "^1.0.9",
"yup": "^0.26.6"
},
"devDependencies": {
"babel-core": "^6.21.0",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-3": "^6.24.1",
"copy-webpack-plugin": "^4.6.0",
"file-loader": "^3.0.1",
"html-webpack-plugin": "^2.26.0",
"less": "^3.9.0",
"less-loader": "^4.1.0",
"path": "^0.12.7",
"url-loader": "^1.1.2",
"webpack": "3.6.0",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "2.11.3"
}
}
src/index.html:
<html lang="en">
<head>
<base href="/" />
<meta charset="UTF-8">
<meta
name="viewport"
content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no"
>
<title>dashboard</title>
<link rel="shortcut icon" href="assets/favicon.ico">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
<!--<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />-->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css">
<style>
a { cursor: pointer; text-decoration: none }
.help-block { font-size: 12px; }
body{
margin: 0;
/*background-color: #f5f5f5;*/
background-color: #232122;
}
</style>
<!-- Hotjar Tracking Code for https://www.dashboard.mltrons.com -->
<script>
(function(h,o,t,j,a,r){
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
h._hjSettings={hjid:1317845,hjsv:6};
a=o.getElementsByTagName('head')[0];
r=o.createElement('script');r.async=1;
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
a.appendChild(r);
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
</script>
</head>
<body>
<div id="app"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>-->
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/gojs/1.8.35/go.js"></script>-->
<script src="assets/js/go.js"></script>
<script src="assets/js/extension.js"></script>
<script src="https://static.landbot.io/landbot-widget/landbot-widget-1.0.0.js"></script>
</body>
</html>
src/index.jsx:
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { store } from './_helpers';
import { App } from './App';
render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('app')
);
If u need anything else please let me know.thanks

You should add all of webpack.optimize plugins only in production. Turn it off in development and it will take a little less time.
if (PRODUCTION) {
config.plugins.push(
...your optimize plugins here
);
}

Related

Getting 404 on angular application load

I have upgraded my angular application from version 12 to 14. I'm using custom Webpack. In MVC view I have added the main.js script. But on page load I'm getting 404 for all the HTML & CSS pages. I need to generate 2 output files main.js & main.bo.js. Based on the user role I'm loading corresponding MVC page. One view is for front end application where I'm registering main.js & another view is for back office where I'm registering main.bo.js.
When the application is loading I'm getting 404 for all the html pages & css.
Tried many options but not able to resolve the issue. Any help will be appreciated.
Error Details
I'm using custom webpack because I need 2 entry point main.js and main.bo.bundle.js. Based on the creds I'm registering either main.js or main.bundle.bo in my mvc application.
This is how I'm registering script from MVC view.
Scripts
Wepback.config.js
"use strict";
const path = require('path');
const webpack = reiuire('webpack');
const CssMinimizer = require('css-minimizer-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserPlugin = require("terser-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
module.exports = {
mode: "development", // "production" | "development" | "none"
entry: {
//'polyfills': './angular/src/polyfills.ts',
'vendor': './angular/src/vendor.ts',
'app': './angular/src/main.ts',
'bo': './angular/src/main.bo.ts'
},
output: {
path: path.resolve(__dirname, '../dist'),
filename: '[name].bundle.js',
libraryTarget: 'umd',
clean: true
},
module: {
rules: [
{
test: /\.m?js$/,
use: {
loader: 'babel-loader',
options: {
plugins: ['#angular/compiler-cli/linker/babel'],
compact: false,
cacheDirectory: true,
}
}
},
{
test: /src\/.*\.js$/,
use: [
{
loader: 'babel-loader',
options: {
sourceMaps: false,
cacheDirectory: true,
cacheCompression: false
}
},
...(
[{ loader: 'source-map-loader' }]
)
],
exclude: [/(node_modules|bower_components)/]
},
{
test: /\.tsx?$/,
use: [
{
loader: 'ts-loader',
options: {
onlyCompileBundledFiles: true
}
}
],
exclude: [/node_modules/, /test/]
},
{
test: /\.(html)$/,
use: 'html-loader'
},
{
test: /src\/app\/.*\.css$/,
use: [
'style-loader',
'css-loader'
]
},
]
},
resolve: {
extensions: ['.mjs', '.ts', '.js', '.css', '.html'],
fallback: {
crypto: "crypto-browserify",
http: "stream-http",
https: "https-browserify",
os: "os-browserify/browser",
path: "path-browserify",
stream: "stream-browserify",
process: "process/browser",
zlib: "browserify-zlib",
url: "url/",
},
},
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000
},
devtool: 'source-map',
target: "web",
plugins: [
new webpack.ContextReplacementPlugin(
/\#angular(\\|\/)core(\\|\/)esm5/,
'./angular',
{}
),
new MiniCssExtractPlugin(),
new HtmlWebpackPlugin(),
new webpack.SourceMapDevToolPlugin({
filename: '[name].js.map',
exclude: ['vendor.ts']
})
],
optimization: {
minimize: false,
minimizer: [
new TerserPlugin({
exclude: /assets/,
extractComments: false
})
]
}
}
Package.json
"devDependencies": {
"#angular-builders/custom-webpack": "^14.0.0",
"#angular-builders/dev-server": "^7.3.1",
"#angular-devkit/build-angular": "^14.0.0",
"#angular/cli": "^14.0.0",
"#angular/compiler-cli": "^14.0.0",
"#babel/plugin-proposal-decorators": "^7.18.9",
"#ngtools/webpack": "11.0.7",
"#types/jasmine": "~4.0.0",
"#types/jest": "^27.4.1",
"#webpack-cli/serve": "^1.6.1",
"babel-loader": "^8.2.5",
"css-loader": "^5.2.7",
"css-minimizer-webpack-plugin": "^4.0.0",
"extract-text-webpack-plugin": "^2.1.0",
"file-loader": "^6.2.0",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^5.5.0",
"jasmine-core": "~4.1.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-html-detailed-reporter": "^1.1.20",
"karma-jasmine": "~5.0.0",
"karma-jasmine-html-reporter": "~1.7.0",
"karma-phantomjs-launcher": "^1.0.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.4",
"lodash": "^4.17.21",
"mini-css-extract-plugin": "^2.6.1",
"phantomjs": "^1.9.19",
"raw-loader": "^4.0.2",
"style-loader": "^2.0.0",
"terser-webpack-plugin": "^5.3.3",
"to-string-loader": "^1.2.0",
"ts-loader": "^9.3.1",
"typescript": "~4.7.2",
"uglifyjs-webpack-plugin": "^1.1.2",
"url": "^0.11.0",
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.9.3",
"webpack-merge": "^5.8.0"
},
"dependencies": {
"#angular/animations": "^14.0.0",
"#angular/cdk": "^14.0.0",
"#angular/cli": "14.0.0",
"#angular/common": "^14.0.0",
"#angular/compiler": "^14.0.0",
"#angular/core": "^14.0.0",
"#angular/forms": "^14.0.0",
"#angular/material": "^14.0.0",
"#angular/platform-browser": "^14.0.0",
"#angular/platform-browser-dynamic": "^14.0.0",
"#angular/router": "^14.0.0",
"#babel/core": "^7.18.9",
"#babel/preset-env": "^7.18.9",
"#ng-idle/core": "^11.1.0",
"#ng-idle/keepalive": "^11.0.3",
"#types/node": "14.17.3",
"#types/webrtc": "^0.0.30",
"angular2-template-loader": "^0.6.2",
"assert": "^2.0.0",
"browserify-zlib": "^0.2.0",
"canvg": "^3.0.7",
"classlist.js": "^1.1.20150312",
"codelyzer": "^0.0.28",
"core-js": "^3.23.5",
"crypto-browserify": "^3.12.0",
"enhanced-resolve": "3.3.0",
"font-awesome": "^4.7.0",
"html2canvas": "1.0.0-alpha.9",
"https-browserify": "^1.0.0",
"ie-shim": "^0.1.0",
"jspdf": "^2.4.0",
"ng2-material-dropdown": "^0.11.0",
"ng2-pdf-viewer": "^3.0.8",
"ngx-bootstrap": "^6.2.0",
"ngx-toastr": "^14.2.1",
"node": "^18.5.0",
"node-fetch": "^2.6.1",
"oidc-client": "^1.10.1",
"os-browserify": "^0.3.0",
"pdfjs-dist": "^2.14.305",
"primeng": "^14.0.0-rc.1",
"rxjs": "~7.5.0",
"rxjs-compat": "^6.6.7",
"rxjs-tslint": "^0.1.8",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"tsconfig-paths-webpack-plugin": "^4.0.0",
"tslib": "^2.3.0",
"typescript-base64-arraybuffer": "^0.1.0",
"web-animations-js": "^2.3.1",
"yarn": "^1.22.17",
"zone.js": "^0.10.3"
},
"-vs-binding": {
"ProjectOpened": [
"test"
]
},
"browser": {
"zlib": false
}
TSConfig -
{
"compileOnSave": false,
"buildOnSave": false,
"compilerOptions": {
"baseUrl": "./",
// "outDir": "./dist",
// "forceConsistentCasingInFileNames": false,
"strict": false,
//"noImplicitOverride": true,
//"noPropertyAccessFromIndexSignature": true,
//"noImplicitReturns": false,
"noImplicitAny": false,
"strictPropertyInitialization": false,
//"noFallthroughCasesInSwitch": true,
"strictNullChecks": false,
"sourceMap": true,
"declaration": false,
//"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
//"importHelpers": true,
"target": "es5",
"module": "esnext",
"lib": [
"ES6",
"dom"
],
"paths" : {
"crypto": ["./node_modules/crypto-browserify"],
"stream": ["./node_modules/stream-browserify"],
"assert": ["./node_modules/assert"],
"http": ["./node_modules/stream-http"],
"https": ["./node_modules/https-browserify"],
"os": ["./node_modules/os-browserify"],
"zlib": ["./node_modules/browserify-zlib"]
},
},
"angularCompilerOptions": {
"compilationMode": "partial"
}
}
Index.html file from dist folder.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Webpack App</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1"><script defer src="vendor.bundle.js"></script><script defer src="app.bundle.js"></script><script defer src="bo.bundle.js"></script></head>
<body>
</body>
</html>

Webpack HMR not updating in html file

I am using webpack 5 now and using HMR for hot module replacements. But It shows in console that hmr working but that is not updating in HTML file.
My webpack.config.js file is:
const path = require('path');
module.exports = {
entry: {
bundle: './src/index.js'
},
output: {
path: path.resolve( __dirname, 'assets' ),
filename: '[name].js'
},
mode: 'development',
module: {
rules: [
{
test: /\.(js)$/,
exclude: /node_modules/,
use: [ 'babel-loader']
},
{
test: /\.s[ac]ss$/,
use: ['style-loader', 'css-loader', 'sass-loader']
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'sass-loader']
},
{
test: /\.less$/,
use: [{
loader: "style-loader"
}, {
loader: "css-loader"
}, {
loader: "less-loader",
options: {
lessOptions: {
javascriptEnabled: true
}
}
}]
}
]
},
devServer : {
headers: {
'Access-Control-Allow-Origin': '*'
},
client: {
progress: true,
},
allowedHosts: 'all',
hot: true,
static: {
directory: path.join(__dirname, 'dist')
},
}
}
My package.json is
{
"name": "booking",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "cross-env BABEL_ENV=default NODE_ENV=production webpack",
"start": "webpack-dev-server --hot"
},
"author": "",
"license": "ISC",
"dependencies": {
"#ant-design/icons": "^4.7.0",
"#headlessui/react": "^1.4.1",
"#heroicons/react": "^1.0.4",
"#reduxjs/toolkit": "^1.6.1",
"#tailwindcss/forms": "^0.3.4",
"antd": "^4.16.13",
"axios": "^0.21.4",
"bootstrap-icons": "^1.5.0",
"date-fns": "^2.24.0",
"moment": "^2.29.1",
"react": "^17.0.2",
"react-bootstrap-icons": "^1.5.0",
"react-dom": "^17.0.2",
"react-multi-date-picker": "^3.1.7",
"react-nice-dates": "^3.1.0",
"react-redux": "^7.2.5",
"react-smooth-list": "^1.0.2",
"redux": "^4.1.1"
},
"devDependencies": {
"#babel/core": "^7.15.5",
"#babel/preset-env": "^7.15.6",
"#babel/preset-react": "^7.14.5",
"autoprefixer": "^10.3.4",
"babel-loader": "^8.2.2",
"babel-plugin-import": "^1.13.3",
"cross-env": "^7.0.3",
"css-loader": "^6.2.0",
"html-webpack-plugin": "^5.5.0",
"less": "^4.1.2",
"less-loader": "^10.2.0",
"node-sass": "^6.0.1",
"postcss": "^8.3.6",
"sass": "^1.39.2",
"sass-loader": "^12.1.0",
"style-loader": "^3.2.1",
"tailwindcss": "^2.2.15",
"webpack": "^5.52.0",
"webpack-cli": "^4.8.0",
"webpack-dev-server": "^4.7.4"
}
}
My main problem is its compiling in the console but not updating in htm file actually..I have mentioned if (module.hot) module.hot.accept() in my ./src/index.js file, but its not working yet.Anything I need to do more to get this working!
My ./dist/index.html is:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="wp-booking-press-container"></div>
<script src="bundle.js"></script>
</body>
</html>

Unexpected token error when on Webpack load

I tried to setup my own toolchain to build a React app. I'm using Webpack with Typescript React.
package.json
{
"name": "library2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint '**/*.{tsx,js,ts}'",
"lint:fix": "eslint --fix '**/*.{tsx,js,ts}'",
"start": "webpack-dev-server --mode development"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"pg": "^8.3.0",
"prettier": "^2.0.5",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"typescript": "^3.9.5"
},
"devDependencies": {
"#babel/cli": "^7.10.4",
"#babel/core": "^7.10.4",
"#babel/plugin-proposal-class-properties": "^7.10.4",
"#babel/preset-env": "^7.10.4",
"#babel/preset-react": "^7.10.4",
"#types/node": "^14.0.20",
"#types/react": "^16.9.41",
"#types/react-dom": "^16.9.8",
"#typescript-eslint/eslint-plugin": "^3.1.0",
"#typescript-eslint/parser": "^3.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"css-loader": "^3.6.0",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.1.0",
"eslint-plugin-import": "^2.21.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.20.0",
"eslint-plugin-react-hooks": "^2.5.1",
"style-loader": "^1.2.1",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
}
}
webpack.config.js
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: './src/App.tsx',
mode: 'development',
module: {
rules: [
{
test: /\.(|ts|tsx|js|jsx)$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: [
'#babel/preset-env',
'#babel/preset-react',
],
plugins: [
'#babel/plugin-proposal-class-properties',
],
},
},
},
{ // rules for css
test: /\.(css|scss)$/,
use: ['style-loader', 'css-loader'],
},
],
},
resolve: { extensions: ['.ts', '.tsx', '.js', '.jsx'] },
output: {
path: path.resolve(__dirname, 'dist/'),
publicPath: '/dist/',
filename: 'bundle.js',
},
devServer: {
contentBase: path.join(__dirname, 'public/'),
port: 3000,
publicPath: 'http://localhost:3000/dist/',
hotOnly: true,
},
plugins: [new webpack.HotModuleReplacementPlugin()],
};
.babelrc
{
"presets": ["#babel/preset-env", "#babel/preset-react"],
"plugins": ["#babel/plugin-proposal-class-properties"]
}
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="main"></div>
<script src="../dist/bundle.js"></script>
</body>
</html>
App.tsx
import React from 'react';
import { render } from 'react-dom';
import Hello from './Hello';
render(<Hello />, document.querySelector('#main'));
Hello.tsx
import React from 'react';
import './hello.scss';
export default class Hello extends React.Component {
vark: number;
test() {
this.vark = 1;
}
render() {
return (
<div className="hello">Hello!</div>
);
}
}
I get the following error when webpack builds (npm run start):
ERROR in ./src/Hello.tsx
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/JAAI/Desktop/Library2/src/Hello.tsx: Unexpected token (5:6)
3 |
4 | export default class Hello extends React.Component {
> 5 | vark: number;
| ^
6 |
7 | test() {
8 | this.vark = 1;
at Object._raise (/Users/JAAI/Desktop/Library2/node_modules/#babel/parser/lib/index.js:757:17)
at Object.raiseWithData (/Users/JAAI/Desktop/Library2/node_modules/#babel/parser/lib/index.js:750:17)
at Object.raise (/Users/JAAI/Desktop/Library2/node_modules/#babel/parser/lib/index.js:744:17)
at Object.unexpected (/Users/JAAI/Desktop/Library2/node_modules/#babel/parser/lib/index.js:8834:16)
at Object.parseClassMemberWithIsStatic (/Users/JAAI/Desktop/Library2/node_modules/#babel/parser/lib/index.js:12169:12)
at Object.parseClassMember (/Users/JAAI/Desktop/Library2/node_modules/#babel/parser/lib/index.js:12062:10)
at /Users/JAAI/Desktop/Library2/node_modules/#babel/parser/lib/index.js:12007:14
at Object.withTopicForbiddingContext (/Users/JAAI/Desktop/Library2/node_modules/#babel/parser/lib/index.js:11078:14)
at Object.parseClassBody (/Users/JAAI/Desktop/Library2/node_modules/#babel/parser/lib/index.js:11984:10)
at Object.parseClass (/Users/JAAI/Desktop/Library2/node_modules/#babel/parser/lib/index.js:11958:22)
# ./src/App.tsx 3:0-28 4:41-46
ℹ 「wdm」: Failed to compile.
At first I thought this was because the Webpack env and react presets didn't allow for class properties so I included the class properties plugin but the error persisted. Note that if I remove that line it builds successfully.

how can I solve this problem? `You may need an appropriate loader to handle this file type.` scss react

I wanna to use GoGO template in React, but i have this problem.
Uncaught Error: Module parse failed: Unexpected token (29:12)
You may need an appropriate loader to handle this file type.
|
| var render = function render() {
> var css = import('./assets/css/sass/themes/gogo.' + color + '.scss').then(function (x) {
| var MainApp = require('./App').default;
|
at eval (index.js:1)
at Object../src/index.js (main.f444d441.js:6169)
at __webpack_require__ (main.f444d441.js:724)
at fn (main.f444d441.js:101)
at eval (webpack:///multi_(:3005/webpack)-dev-server/client?:5:18)
at Object.0 (main.f444d441.js:6180)
at __webpack_require__ (main.f444d441.js:724)
at main.f444d441.js:791
at main.f444d441.js:794
I tried different approuch but I can't solved this problem.
This is a link to source code page.
https://themeforest.net/item/gogo-react-bootstrap-4-admin-dashboard/22544383/comments?page=5
webpack.config.js
'use strict';
/**
* Webpack Config
*/
const path = require('path');
const fs = require('fs');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
// Webpack uses `publicPath` to determine where the app is being served from.
// In development, we always serve from the root. This makes config easier.
const publicPath = '/';
// Make sure any symlinks in the project folder are resolved:
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
// plugins
const HtmlWebPackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CleanWebpackPlugin = require('clean-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const CopyWebpackPlugin = require('copy-webpack-plugin');
// the path(s) that should be cleaned
let pathsToClean = [
'dist',
'build'
]
// the clean options to use
let cleanOptions = {
root: __dirname,
verbose: false, // Write logs to console.
dry: false
}
module.exports = {
entry: ["babel-polyfill", "react-hot-loader/patch", "./src/index.js"],
output: {
// The build folder.
path: resolveApp('dist'),
// Generated JS file names (with nested folders).
// There will be one main bundle, and one file per asynchronous chunk.
// We don't currently advertise code splitting but Webpack supports it.
filename: 'assets/js/[name].[hash:8].js',
chunkFilename: 'assets/js/[name].[hash:8].chunk.js',
// We inferred the "public path" (such as / or /my-project) from homepage.
publicPath: publicPath,
hotUpdateChunkFilename: 'hot/hot-update.js',
hotUpdateMainFilename: 'hot/hot-update.json'
},
devServer: {
contentBase: './src/index.js',
compress: true,
port: 3005, // port number
historyApiFallback: true,
quiet: true
},
// resolve alias (Absolute paths)
resolve: {
alias: {
Components: path.resolve(__dirname, 'src/components/'),
Containers: path.resolve(__dirname, 'src/containers/'),
Assets: path.resolve(__dirname, 'src/assets/'),
Util: path.resolve(__dirname, 'src/util/'),
Routes: path.resolve(__dirname, 'src/routes/'),
Constants: path.resolve(__dirname, 'src/constants/'),
Redux: path.resolve(__dirname, 'src/redux/'),
Data: path.resolve(__dirname, 'src/data/')
}
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.html$/,
use: [
{
loader: "html-loader",
options: { minimize: true }
}
]
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader"]
},
// Scss compiler
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"sass-loader",
"style-loader",
// "postcss-loader"
]
},
// {
// test: /\.scss$/,
// use: ExtractTextPlugin.extract({
// use: [{
// loader: "css-loader"
// }, {
// loader: "sass-loader"
// }],
// fallback: "style-loader"
// })
// }
// {
// test: /\.scss$/,
// use: [
// 'style-loader',
// 'css-loader',
// 'postcss-loader',
// 'sass-loader',
// 'postcss-loader'
// {
// loader: 'sass-resources-loader',
// options: {
// // Provide path to the file with resources
// resources: 'src/assets/css/sass/themes/gogo.light.purple.scss',
//
// // Or array of paths
// // resources: ['./path/to/vars.scss', './path/to/mixins.scss']
// },
// },
// ],
// },
]
},
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
uglifyOptions: {
compress: false,
ecma: 6,
mangle: true
},
sourceMap: true
}),
new OptimizeCSSAssetsPlugin({})
]
},
performance: {
hints: process.env.NODE_ENV === 'production' ? "warning" : false
},
plugins: [
new CopyWebpackPlugin([
{from:'src/assets/img',to:'assets/img'},{from:'src/assets/fonts',to:'assets/fonts'}
]),
new FriendlyErrorsWebpackPlugin(),
new CleanWebpackPlugin(pathsToClean, cleanOptions),
new HtmlWebPackPlugin({
template: "./public/index.html",
filename: "./index.html",
favicon: './public/favicon.ico'
}),
new MiniCssExtractPlugin({
filename: "assets/css/[name].[hash:8].css"
})
]
};
package.json
{
"name": "gogo-react",
"version": "2.0.2",
"description": "Gogo - React Bootstrap 4 Admin Dashboard Template",
"scripts": {
"start": "webpack-dev-server --mode development --hot --progress --open",
"build": "webpack --mode production"
},
"keywords": [
"reactjs"
],
"author": "Colored Strategies",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-eslint": "^7.2.3",
"babel-loader": "^7.1.4",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"clean-webpack-plugin": "^0.1.19",
"copy-webpack-plugin": "^4.5.2",
"css-loader": "^2.0.0",
"eslint": "^4.19.1",
"eslint-config-react-app": "^2.1.0",
"eslint-plugin-flowtype": "^2.47.1",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.8.2",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^1.1.11",
"friendly-errors-webpack-plugin": "^1.7.0",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "^0.5.0",
"node-sass": "^4.8.3",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-hot-loader": "^4.1.3",
"sass-loader": "^7.1.0",
"uglifyjs-webpack-plugin": "^1.2.5",
"url-loader": "^1.0.1",
"webpack": "^4.27.1",
"webpack-bundle-analyzer": "^2.11.1",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.10"
},
"dependencies": {
"#date-io/moment": "0.0.2",
"availity-reactstrap-validation": "^2.0.4",
"axios": "^0.18.0",
"chart.js": "^2.7.2",
"chartjs-plugin-datalabels": "^0.3.0",
"classnames": "2.2.6",
"draft-js": "^0.10.5",
"fine-uploader": "^5.16.2",
"firebase": "^5.3.0",
"formik": "^1.5.4",
"install": "^0.12.2",
"jalali-moment": "^3.3.1",
"jwt-decode": "^2.2.0",
"material-ui": "^0.20.2",
"material-ui-persian-date-picker-utils": "^0.1.2",
"material-ui-pickers": "^2.0.4",
"moment": "^2.22.2",
"npm": "^6.5.0",
"postcss-loader": "^3.0.0",
"rc-slider": "^8.6.1",
"rc-switch": "^1.6.0",
"react": "^16.4.1",
"react-autosuggest": "^9.3.4",
"react-big-calendar": "^0.19.2",
"react-block-ui": "^1.1.3",
"react-chartjs-2": "^2.7.4",
"react-circular-progressbar": "^1.0.0",
"react-contextmenu": "^2.9.4",
"react-datepicker": "^1.5.0",
"react-dom": "^16.4.1",
"react-fine-uploader": "^1.1.0",
"react-headroom": "^2.2.4",
"react-intl": "2.4.0",
"react-lines-ellipsis": "^0.13.2",
"react-loadable": "5.4.0",
"react-mousetrap": "^0.2.0",
"react-perfect-scrollbar": "^1.1.1",
"react-quill": "^1.3.1",
"react-rater": "^5.0.3",
"react-redux": "5.0.7",
"react-router-dom": "^4.2.2",
"react-scroll-to-component": "^1.0.2",
"react-select": "^2.0.0-beta.7",
"react-sortablejs": "^1.3.6",
"react-table": "^6.8.6",
"react-tagsinput": "^3.19.0",
"react-transition-group": "^1.2.0",
"reactstrap": "^6.5.0",
"redux": "4.0.0",
"redux-saga": "^0.16.0",
"sass-resources-loader": "^2.0.0",
"sortablejs": "^1.6.1",
"style-loader": "^0.23.1",
"sweetalert2": "^8.8.7",
"video.js": "^7.3.0",
"yup": "^0.27.0"
}
}
Please help me, thanks in advance.
If you are using latest version of react then no need to set loader in webpack.config.js file.
You can directly do this,
npm install sass-loader
And you can start using your scss files in the project.
It is about files which start with a dot being hidden by his os and failing to copy them.
In project directory there should be a ”.babelrc” and ”.eslintrc” files and the problem occurs when ”.babelrc” file is missing. Maybe you should also check it when you have time.

Webpack/Babel/Angular - bundle.js 404 (Not Found)

I'm having some trouble getting my bundle file to load in my html. Each time it returns 404. I have checked, and the Bundle is building fine.
package.json:
{
"name": "MyApp",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"bundle": "webpack"
},
"repository": {
"type": "git",
"url": ""
},
"author": "",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": "",
"dependencies": {
"angular": "^1.5.8",
"angular-jwt": "^0.1.7",
"angular-resource": "^1.5.8",
"angular-ui-router": "^0.3.1",
"bcrypt": "^0.8.7",
"cookie-parser": "^1.4.3",
"cors": "^2.8.1",
"debug": "^2.2.0",
"express": "^4.14.0",
"gulp": "^3.9.1",
"json-loader": "^0.5.4",
"jsonwebtoken": "^7.1.9",
"main-bower-files": "^2.13.1",
"mongoose": "^4.6.3",
"morgan": "^1.7.0",
"node-schedule": "^1.2.0",
"nodemailer": "^2.6.4",
"request-promise": "^4.1.1",
"run-sequence": "^1.2.2",
"sass": "^0.5.0",
"satellizer": "^0.15.5"
},
"devDependencies": {
"babel": "^6.5.2",
"babel-angular": "0.0.5",
"babel-core": "^6.18.0",
"babel-loader": "^6.2.5",
"babel-preset-angular": "^6.0.15",
"babel-preset-es2015": "^6.18.0",
"chai": "^3.5.0",
"chai-http": "^3.0.0",
"gulp": "^3.9.1",
"gulp-clean-css": "^2.0.13",
"gulp-concat": "^2.6.0",
"gulp-filter": "^4.0.0",
"gulp-livereload": "^3.8.1",
"gulp-nodemon": "^2.2.1",
"gulp-notify": "^2.2.0",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4",
"gulp-sass": "^2.3.2",
"gulp-uglify": "^2.0.0",
"mocha": "^3.1.2",
"node-sass": "^3.10.1",
"sass-loader": "^4.0.2",
"webpack": "^1.13.2",
"webpack-node-externals": "^1.5.4"
}
}
.babelrc:
{
"presets": [
'es2015', 'angular', 'stage-0'
]
}
webpack.config.js:
var webpack = require('webpack');
var nodeExternals = require('webpack-node-externals');
module.exports = {
target: 'node',
externals: [nodeExternals()],
entry: './app.js',
output: {
path: __dirname + '/app',
filename: './bundle.js'
},
module: {
loaders: [
{
test: /\.js$/,
exclude: '/(node_modules)/',
loader: 'babel'
},
{
test: /\.scss$/,
loader: 'style-loader!css-loader!sass-loader'
}
]
}
}
index.html head:
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<title>MyApp</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<link rel="stylesheet" href="./css/reset.css">
<link rel="stylesheet" href="./css/app.css">
<link href="https://fonts.googleapis.com/css?family=Raleway:400,600" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-resource.min.js"></script>
<script src="//npmcdn.com/angular-ui-router/release/angular-ui-router.min.js"></script>
<script src="//cdn.jsdelivr.net/satellizer/0.13.1/satellizer.min.js"></script>
<script src="https://cdn.rawgit.com/auth0/angular-jwt/master/dist/angular-jwt.js"></script>
<script src="/js/app.js"></script>
<script src="bundle.js"></script>
Any help much appreciated.
Try changing output in the webpack config file:
var webpack = require('webpack');
var nodeExternals = require('webpack-node-externals');
var here = require('path-here'); // <- Add path-here
module.exports = {
target: 'node',
externals: [nodeExternals()],
entry: './app.js',
output: {
path: here('dist'), // <- changed to this
filename: 'bundle.js' // <- changed to this
},
module: {
loaders: [
{
test: /\.js$/,
exclude: '/(node_modules)/',
loader: 'babel'
},
{
test: /\.scss$/,
loader: 'style-loader!css-loader!sass-loader'
}
]
}
}
Let me know if this helps.

Resources