Hi i have problem with babel-loader it write me
ERROR in ./src/js/pages/Admin/views/Pages/Register/Register.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: C:\Projekty\eshop_frontend_template\src\js\pages\Admin\views\Pages\Register\Register.js: Unexpected token (7:6)
> 5 | render() {
6 | return (
> 7 | <div className="app flex-row align-items-center">
| ^
8 | <Container>
9 | <Row className="justify-content-center">
10 | <Col md="6">
at Parser.raise (C:\Projekty\eshop_frontend_template\node_modules\#babel\parser\lib\index.js:3939:15)
at Parser.unexpected (C:\Projekty\eshop_frontend_template\node_modules\#babel\parser\lib\index.js:5248:16)
at Parser.parseExprAtom (C:\Projekty\eshop_frontend_template\node_modules\#babel\parser\lib\index.js:6328:20)
at Parser.parseExprSubscripts (C:\Projekty\eshop_frontend_template\node_modules\#babel\parser\lib\index.js:5924:21)
at Parser.parseMaybeUnary (C:\Projekty\eshop_frontend_template\node_modules\#babel\parser\lib\index.js:5903:21)
at Parser.parseExprOps (C:\Projekty\eshop_frontend_template\node_modules\#babel\parser\lib\index.js:5812:21)
at Parser.parseMaybeConditional (C:\Projekty\eshop_frontend_template\node_modules\#babel\parser\lib\index.js:5784:21)
at Parser.parseMaybeAssign (C:\Projekty\eshop_frontend_template\node_modules\#babel\parser\lib\index.js:5731:21)
at Parser.parseParenAndDistinguishExpression (C:\Projekty\eshop_frontend_template\node_modules\#babel\parser\lib\index.js:6474:28)
at Parser.parseExprAtom (C:\Projekty\eshop_frontend_template\node_modules\#babel\parser\lib\index.js:6284:21)
# ./src/js/pages/Admin/views/Pages/index.js 37:39-60
# ./src/js/pages/Admin/Admin.js
# ./src/index.js
# multi (webpack)-dev-server/client?http://localhost:8080 (webpack)/hot/dev-server.js ./src/index.js
5 | render() {
6 | return (
> 7 | <div className="app flex-row align-items-center">
| ^
8 | <Container>
10 | <Col md="6">
my webpack.config.js
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
plugins: ['#babel/proposal-class-properties']
}
}
},
{ test: /\.css$/, loader: "style-loader!css-loader" },
{ test: /\.json$/, loader: "json-loader" },
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader? limit=100000' },
{
test: /\.scss$/,
use: [
"style-loader", // creates style nodes from JS strings
"css-loader", // translates CSS into CommonJS
"sass-loader" // compiles Sass to CSS, using Node Sass by default
]
}
]
},
resolve: {
extensions: ['*', '.js', '.jsx']
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
template: './dist/index.html'
})
],
my package.json#babel
"babel": {
"presets": [
[
"#babel/preset-env",
{
"modules": "commonjs",
"targets": {
"node": "current"
}
}
],
"#babel/preset-react"
],
"plugins": [
[
"#babel/plugin-proposal-decorators",
{
"legacy": true
}
]
]
},
my dependencies
"devDependencies": {
"#babel/core": "^7.1.0",
"#babel/preset-env": "^7.1.0",
"#babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.2",
"css-loader": "^1.0.0",
"react-hot-loader": "^4.3.11",
"style-loader": "^0.23.0",
"webpack": "^4.20.1",
"webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.1.9"
},
"dependencies": {
"#babel/plugin-proposal-class-properties": "^7.1.0",
"#babel/plugin-proposal-decorators": "^7.1.0",
"#babel/polyfill": "^7.0.0",
"#coreui/coreui": "^2.0.9",
"#coreui/react": "^2.0.5",
"axios": "^0.18.0",
"css-loader": "^1.0.0",
"file-loader": "^2.0.0",
"flag-icon-css": "^3.2.0",
"font-awesome": "^4.7.0",
"html-webpack-plugin": "^3.2.0",
"json-loader": "^0.5.7",
"node-sass": "^4.9.3",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-localize-redux": "^3.4.0",
"react-redux": "^5.0.7",
"react-router-dom": "^4.3.1",
"redux": "^4.0.0",
"redux-localstorage-simple": "^2.1.4",
"redux-logger": "^3.0.6",
"redux-promise-middleware": "^5.1.1",
"redux-thunk": "^2.3.0",
"sass-loader": "^7.1.0",
"simple-line-icons": "^2.4.1",
"style-loader": "^0.23.0",
"universal-cookie": "^3.0.4"
}
I tried some helps on forums but nothing helped. Can you say me please what i have wrong?
I am using Babel 7
Thank you :)
I checked on my notebook, You have just lot of entries missing in package.json and You are using not supported features. After changing these files run 'npm install' and npm start should wotk :)
package.json
{
"name": "eshop_frontend_template",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --config ./webpack.config.js --mode development",
"build": "webpack -p --progres --config ./webpack.config.js --mode production",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://d3tr1tus#bitbucket.org/d3tr1tus/eshop_frontend_template.git"
},
"keywords": [],
"author": "Filip Březina <filip.brezina11#gmail.com> (localhost:8080)",
"license": "MIT",
"babel": {
"presets": [
"#babel/preset-env",
"#babel/preset-react"
],
"plugins": [
[
"#babel/plugin-proposal-decorators",
{
"legacy": true
}
]
]
},
"devDependencies": {
"#babel/core": "^7.1.0",
"#babel/plugin-syntax-dynamic-import": "^7.0.0",
"#babel/preset-env": "^7.1.0",
"#babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.2",
"css-loader": "^1.0.0",
"html-webpack-plugin": "^3.2.0",
"react-hot-loader": "^4.3.11",
"style-loader": "^0.23.0",
"url-loader": "^1.1.1",
"webpack": "^4.20.1",
"webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.1.9"
},
"dependencies": {
"#babel/plugin-proposal-class-properties": "^7.1.0",
"#babel/plugin-proposal-decorators": "^7.1.0",
"#babel/polyfill": "^7.0.0",
"#coreui/coreui": "^2.0.9",
"#coreui/coreui-plugin-chartjs-custom-tooltips": "^1.2.0",
"#coreui/react": "^2.0.5",
"axios": "^0.18.0",
"chart.js": "^2.7.2",
"css-loader": "^1.0.0",
"file-loader": "^2.0.0",
"flag-icon-css": "^3.2.0",
"font-awesome": "^4.7.0",
"json-loader": "^0.5.7",
"node-sass": "^4.9.3",
"react": "^16.5.2",
"react-chartjs-2": "^2.7.4",
"react-dom": "^16.5.2",
"react-loadable": "^5.5.0",
"react-localize-redux": "^3.4.0",
"react-redux": "^5.0.7",
"react-router-dom": "^4.3.1",
"reactstrap": "^6.4.0",
"redux": "^4.0.0",
"redux-localstorage-simple": "^2.1.4",
"redux-logger": "^3.0.6",
"redux-promise-middleware": "^5.1.1",
"redux-thunk": "^2.3.0",
"sass-loader": "^7.1.0",
"simple-line-icons": "^2.4.1",
"style-loader": "^0.23.0",
"universal-cookie": "^3.0.4"
}
}
webpack.config.js
const webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: "./src/index.js",
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['#babel/preset-env','#babel/react'],
plugins: ['#babel/proposal-class-properties', '#babel/plugin-proposal-object-rest-spread', '#babel/plugin-syntax-dynamic-import']
}
}
},
{ test: /\.css$/, use: [ 'style-loader', 'css-loader' ]},
{ test: /\.json$/, loader: "json-loader" },
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' },
{
test: /\.scss$/,
use: [
"style-loader", // creates style nodes from JS strings
"css-loader", // translates CSS into CommonJS
"sass-loader" // compiles Sass to CSS, using Node Sass by default
]
}
]
},
resolve: {
extensions: ['*', '.js', '.jsx']
},
output: {
path: __dirname + '/dist',
publicPath: '/',
filename: 'bundle.js'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
template: './dist/index.html'
})
],
devServer: {
contentBase: './dist',
hot: true
}
};
I found that the error is because of older version of babel which doesn't handle newer versions of react code.
Here's an easy fix :
My problem was of older babel version fixed easily by installing :
npm i #babel/plugin-proposal-class-properties #babel/preset-react #babel/preset-env #babel/core #babel/plugin-transform-runtime --save-dev
In .babelrc file (or in package.json inside "babel" : ) :
{
"presets": [
"#babel/react" ,
"#babel/env" ,
],
"plugins": [
"#babel/plugin-proposal-class-properties"
]
}
Now babel built it successfully after this.
In my case, I only needed the file .babelrc :
{
"presets": ["react"]
}
Related
Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the render er (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app.
I am developing own library of components and using same library in my application through npm link but getting above error while testing.
here is my webpack.config
const path = require('path');
module.exports = {
entry: './src/index.ts',
devtool: 'eval-source-map',
module: {
rules: [
{
// "oneOf" will traverse all following loaders until one will
// match the requirements. When no loader matches it will fall
// back to the "file" loader at the end of the loader list.
oneOf: [
{
test: /\.(tsx|ts|mjs)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
plugins: [['#babel/plugin-proposal-class-properties'], ['#babel/plugin-transform-runtime', { "regenerator": true }]],
presets: ['#babel/preset-env', '#babel/preset-react', '#babel/preset-typescript'],
},
},
},
{
test: /\.mjs$/,
use: {
loader: 'babel-loader',
options: {
presets: ['#babel/preset-env'],
},
},
},
{
test: /\.(css|scss)$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }, { loader: 'sass-loader' }],
},
// "url" loader works like "file" loader except that it embeds assets
// smaller than specified limit in bytes as data URLs to avoid requests.
// A missing `test` is equivalent to a match.
{
exclude: [/\.js$/, /\.ts$/, /\.html$/, /\.json$/],
loader: require.resolve('url-loader'),
options: {
limit: 10000,
name: 'static/media/[name].[hash:8].[ext]',
},
},
],
},
],
},
resolve: {
extensions: ['.mjs', '.js', '.ts', '.tsx', '.json'],
},
output: {
path: path.resolve(__dirname, 'dist/'),
publicPath: '',
filename: 'bundle.js',
libraryTarget: 'commonjs'
}
};
here is my package.json
{
"name": "abc",
"version": "1.0.42",
"description": "A React component library",
"main": "dist/bundle.js",
"types": "dist/types/index.d.ts",
"scripts": {
"test": "jest",
"build:development": "npm-run-all --parallel webpack:watch generate-typings",
"build:production": "npm-run-all webpack:prod generate-typings",
"build:clean": "rmdir /Q /S dist",
"generate-typings": "tsc --declaration --emitDeclarationOnly",
"styleguide": "npx styleguidist server",
"styleguide:build": "npx styleguidist build",
"webpack:watch": "webpack --watch --mode=development",
"webpack:prod": "webpack --mode=production",
"localVersion": "node -p \"require('./package.json').version\"> localVersion.txt",
"serverVersion": "npm view #company/abc version > serverVersion.txt"
},
"repository": {
"type": "git",
"url": "url"
},
"keywords": [
"react",
"components",
"typescript"
],
"author": "Spencer Cousino",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.11.1",
"#babel/plugin-proposal-class-properties": "^7.10.4",
"#babel/preset-env": "^7.11.0",
"#babel/preset-react": "^7.10.4",
"#babel/preset-typescript": "^7.10.4",
"#fortawesome/fontawesome-svg-core": "^1.2.28",
"#fortawesome/free-solid-svg-icons": "^5.13.0",
"#types/enzyme": "^3.10.5",
"#types/fetch-mock": "^7.3.2",
"#types/jest": "^24.9.1",
"#types/nock": "^10.0.3",
"#types/node": "^11.15.9",
"#types/react": "^16.9.0",
"#types/react-dom": "^16.9.0",
"#types/react-table": "^6.8.7",
"async-wait-until": "^1.2.4",
"babel-loader": "^8.1.0",
"css-loader": "^1.0.1",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"fetch-mock": "^7.7.3",
"file-loader": "^3.0.1",
"identity-obj-proxy": "^3.0.0",
"jest": "^25.3.0",
"nock": "^10.0.6",
"node-fetch": "^2.6.1",
"node-sass": "^4.14.1",
"npm-run-all": "^4.1.5",
"oidc-client": "^1.10.1",
"powerbi-report-component": "^1.6.0",
"prettier": "1.17.0",
"react": "^16.14.0",
"react-docgen-typescript": "^1.20.1",
"react-dom": "^16.14.0",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"react-table": "6.10.3",
"react-slick": "^0.23.2",
"react-spinners": "^0.9.0",
"react-styleguidist": "^11.1.5",
"reactstrap": "^8.4.1",
"sass-loader": "^7.3.1",
"ts-jest": "^25.4.0",
"typescript": "^3.8.3",
"url-loader": "^1.1.2",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12"
},
"dependencies": {
"#babel/plugin-transform-runtime": "^7.12.1",
"#babel/runtime": "^7.12.5",
"#company/abc": "0.0.6",
"#company/abc1": "^1.2.0",
"#company/abc2": "^1.0.23",
"#company/abc3": "^1.9.1",
"#company/abc4": "^1.0.1",
"core-js": "^3.8.0",
"date-fns": "^1.30.1",
"react-bingmaps": "^3.6.1",
"react-bootstrap": "^0.32.3",
"react-grid-layout": "^0.16.6",
"react-scripts": "^4.0.3",
"react-tabs": "^3.1.1",
"slick-carousel": "^1.8.1"
},
"peerDependencies": {
"react": "~16.8.4",
"react-dom": "~16.8.4",
"#types/node": "^11.11.6",
"node-fetch": "^2.3.0",
"oidc-client": "^1.7.0",
"powerbi-report-component": "^1.1.3",
"#fortawesome/fontawesome-svg-core": "^1.2.17",
"#fortawesome/free-solid-svg-icons": "^5.8.1",
"react-slick": "^0.23.2",
"react-spinners": "^0.5.3",
"reactstrap": "^8.0.0"
},
"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"setupFilesAfterEnv": [
"./testSetup.ts"
],
"moduleNameMapper": {
"^.+\\.(css|scss)$": "identity-obj-proxy",
"^.+\\.(svg)$": "<rootDir>/src/mocks/fileMock.js"
},
"moduleFileExtensions": [
"js",
"jsx",
"ts",
"tsx"
],
"collectCoverageFrom": [
"**/context-components/**/*.{js,jsx,ts,tsx}"
]
}
}
I have tried multiple ways but none of them worked for me.
Any help will be appreciated.
On a ReactJS project, it is using webpack for building it. Everytime I run the script for production build, it is giving me a development build (getting This page is using the development build of React. from React Developer Tools). I need to get the production build.
The webpack has been configured by some other developer who's not around and I don't have any prior experience with webpack. So I am facing a really hard time to resolve the error.
package.json:
{
"name": "enquiry-form-rnd-2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "cross-env BUILD_ENV=dev webpack-dev-server --config ./webpack.config.js --mode development --progress --colors --port 3002",
"build:stage": "BUILD_ENV=STAGE webpack --mode production",
"build:prod": "BUILD_ENV=prod webpack --mode production"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.4.4",
"#babel/plugin-proposal-class-properties": "^7.4.4",
"#babel/preset-env": "^7.4.4",
"#babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.6",
"babel-plugin-transform-regenerator": "^6.26.0",
"concurrently": "^4.1.0",
"css-loader": "^2.1.1",
"gulp": "^4.0.2",
"gulp-autoprefixer": "^5.0.0",
"gulp-clean": "^0.4.0",
"gulp-install": "^1.1.0",
"gulp-open": "^3.0.1",
"gulp-sass": "^4.0.1",
"gulp-sourcemaps": "^2.6.4",
"node-sass": "^4.12.0",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"url-loader": "^1.1.2",
"webpack": "^4.31.0",
"webpack-cli": "^3.3.2",
"webpack-dev-server": "^3.3.1"
},
"dependencies": {
"babel-polyfill": "^6.26.0",
"cross-env": "^5.2.0",
"google-maps-react": "^2.0.2",
"immutable": "^4.0.0-rc.12",
"moment": "^2.24.0",
"numeral": "^2.0.6",
"react": "^16.8.6",
"react-bootstrap": "^1.0.0-beta.8",
"react-datetime": "^2.16.3",
"react-dom": "^16.8.6",
"react-intl": "^2.8.0",
"react-notifications-component": "^1.1.1",
"react-redux": "^7.0.3",
"react-responsive": "^6.1.2",
"redux": "^4.0.1",
"redux-devtools-extension": "^2.13.8",
"redux-logger": "^3.0.6",
"redux-saga": "^1.0.2",
"reselect": "^4.0.0",
"styled-components": "^4.2.0",
"styled-icons": "^7.14.0",
"validator": "^11.1.0",
"whatwg-fetch": "^3.0.0"
}
}
webpack.config.js:
const webpack = require("webpack");
module.exports = {
entry: ["babel-polyfill", "./src/index.js"],
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ["babel-loader"]
},
{ test: /\.css$/, loader: "style-loader!css-loader" },
{
test: /\.scss$/,
use: [
"style-loader", // creates style nodes from JS strings
"css-loader", // translates CSS into CommonJS
"sass-loader" // compiles Sass to CSS, using Node Sass by default
]
},
{
test: /\.(pdf|jpg|png|gif|svg|ico)$/,
use: [
{
loader: "url-loader"
}
]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
loader: "file-loader"
}
]
},
resolve: {
extensions: ["*", ".js", ".jsx", "css"]
},
output: {
path: __dirname + "/build",
publicPath: "/",
filename: "bundle.js"
},
devServer: {
contentBase: "./dist",
host: "172.16.228.94",
// host: "192.168.2.108",
port: 3002
},
plugins: [
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
"process.env.DEBUG": JSON.stringify(process.env.BUILD_ENV),
"process.env.BUILD_ENV": JSON.stringify(process.env.BUILD_ENV)
})
]
};
I'm getting generated js file in browser when I'm doing npm start.
I'm using
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0",
"webpack-dev-server": "^3.2.1",
"webpack-manifest-plugin": "^2.0.4"
Below is my webpack.config.js.
Please tell me what I'm doing wrong here
I'm getting generated js file on browser when I do npm start.
I'm using
"webpack": "^4.29.6"
"webpack-cli": "^3.3.0"
"webpack-dev-server": "^3.2.1"
Below is my webpack.config.js
Please tell me what I'm doing wrong here.
const cssFilename = 'static/css/style.[hash].css';
module.exports = {
entry: './src/index.js',
externals: [nodeExternals()],
mode: "production",
resolve: {
extensions: ['.js', '.json', '.jsx', '.css', '.svg']
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
include: path.resolve(__dirname, 'src'),
use: {
loader: 'babel-loader',
options: {
presets: ['#babel/env', '#babel/react']
}
}
},
{
test: /\.css?$/,
include: path.resolve(__dirname, 'src'),
exclude: /(node_modules|bower_components)/,
use: ['raw-loader','style-loader','to-string-loader','css-loader']
}
]
},
devtool: 'inline-source-map',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'static/js/bundle.[hash].js',
chunkFilename: 'static/js/bundle.[hash].js',
publicPath: './'
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new HtmlWebpackPlugin({
filename: './index.html',
template: './public/index.html'
})
]
};
Package.json
{
"name": "demo",
"version": "1.0.0",
"description": "demo",
"private": true,
"jest": {
"collectCoverageFrom": [
"src/Actions/"
],
"coverageThreshold": {
"global": {
"branches": 10,
"functions": 10,
"lines": 10,
"statements": 10
}
}
},
"scripts": {
"watch": "webpack --watch",
"start": "webpack-dev-server",
"build": "webpack",
"test": "set CI=true &&jest --coverage"
},
"homepage": ".",
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.2.3",
"#babel/core": "^7.2.3",
"#babel/plugin-proposal-class-properties": "^7.3.0",
"#babel/plugin-syntax-dynamic-import": "^7.2.0",
"#babel/preset-env": "^7.2.3",
"#babel/preset-flow": "^7.0.0",
"#babel/preset-react": "^7.0.0",
"babel-eslint": "9.0.0",
"babel-loader": "^8.0.5",
"babel-register": "^6.26.0",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"jest": "^24.5.0",
"jest-environment-enzyme": "^7.0.1",
"jest-enzyme": "^7.0.1",
"mini-css-extract-plugin": "^0.5.0",
"raw-loader": "^0.5.1",
"react-svg-loader": "^2.1.0",
"source-map-loader": "^0.2.4",
"to-string-loader": "^1.1.5",
"ts-jest": "^23.10.1",
"typescript": "^3.0.3",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0",
"webpack-dev-server": "^3.2.1",
"webpack-manifest-plugin": "^2.0.4"
},
"exclude": [
"node_modules"
],
"dependencies": {
"axios": "^0.18.0",
"axios-mock-adapter": "^1.16.0",
"babel-preset-react-app": "^7.0.2",
"css-loader": "^2.1.1",
"file-loader": "^3.0.1",
"file-saver": "^1.3.8",
"lodash": "^4.17.10",
"postcss-flexbugs-fixes": "^4.1.0",
"postcss-loader": "^3.0.0",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-redux": "^5.1.1",
"redux": "^4.0.0",
"redux-thunk": "^2.3.0",
"style-loader": "^0.23.1",
"url-loader": "^1.1.2",
"webpack-node-externals": "^1.7.2"
}
}
I use in project react library with typescript and ES6 version of javascript. Some ES6 features are not supported by IE11 so I have to use Babel, however my application isn't correctly loaded in IE11
It throws a syntax error here
What cause this problem? This should be solved using this package transform-es2015-arrow-functions or is there some different problem which I overlooked?
package.json
{
"name": "SkodaAuto.C3PO.AdminConsole.Web",
"private": true,
"version": "0.0.0",
"devDependencies": {
"#babel/core": "^7.1.0",
"#babel/preset-env": "^7.1.0",
"#types/webpack": "2.2.15",
"#types/webpack-env": "1.13.0",
"aspnet-webpack": "2.0.1",
"aspnet-webpack-react": "3.0.0",
"awesome-typescript-loader": "3.2.1",
"babel-core": "^6.17.0",
"babel-loader": "^8.0.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-eval": "^6.22.0",
"babel-preset-es2015": "^6.16.0",
"babel-preset-react": "^6.16.0",
"css-loader": "0.28.4",
"eventsource-polyfill": "^0.9.6",
"extract-text-webpack-plugin": "2.1.2",
"file-loader": "^2.0.0",
"less": "3.7.1",
"less-loader": "4.1.0",
"node-noop": "1.0.0",
"style-loader": "0.18.2",
"typescript": "3.0.1",
"url-loader": "^1.1.1",
"webpack": "^4.19.1",
"webpack-cli": "^3.1.1",
"webpack-hot-middleware": "2.18.2",
"webpack-merge": "4.1.0"
},
"dependencies": {
"#babel/polyfill": "^7.0.0",
"#progress/kendo-data-query": "1.4.1",
"#progress/kendo-drawing": "1.5.7",
"#progress/kendo-react-buttons": "1.2.0",
"#progress/kendo-react-dateinputs": "1.2.0",
"#progress/kendo-react-dialogs": "1.2.0",
"#progress/kendo-react-dropdowns": "1.2.0",
"#progress/kendo-react-grid": "1.2.0",
"#progress/kendo-react-inputs": "1.2.0",
"#progress/kendo-react-intl": "1.2.0",
"#progress/kendo-react-layout": "1.2.0",
"#progress/kendo-react-pdf": "1.2.0",
"#progress/kendo-theme-default": "2.54.1",
"#telerik/kendo-intl": "^1.4.2",
"#types/deep-equal": "1.0.1",
"#types/history": "4.6.0",
"#types/prop-types": "15.5.3",
"#types/react": "16.4.2",
"#types/react-dom": "16.0.7",
"#types/react-hot-loader": "3.0.3",
"#types/react-redux": "4.4.45",
"#types/react-router": "4.0.12",
"#types/react-router-dom": "4.0.5",
"#types/react-router-redux": "5.0.3",
"babel-polyfill": "^6.26.0",
"bootstrap-less-port": "0.3.0",
"deep-equal": "1.0.1",
"history": "4.6.3",
"jquery": "3.0.0",
"query-string": "6.1.0",
"react": "16.4.2",
"react-appinsights": "1.0.4",
"react-dom": "16.4.2",
"react-hot-loader": "3.0.0-beta.7",
"react-redux": "5.0.5",
"react-resize-detector": "3.1.1",
"react-router-dom": "4.1.1",
"react-router-redux": "5.0.0-alpha.6",
"redux": "3.7.1",
"redux-form": "7.4.2",
"redux-logger": "3.0.6",
"redux-thunk": "2.2.0",
"serialize-error": "2.1.0"
},
"scripts": {
"build": "webpack --config webpack.config.js",
"build.vendor": "webpack --config webpack.config.vendor.js"
}}
webpack.config.js
const path = require('path');
const webpack = require('webpack');
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const clientBundleOutputDir = './wwwroot/dist';
module.exports = {
devtool: 'inline-source-map',
entry: { 'main-client': './ClientApp/boot-client.tsx' },
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
modules: [
'./node_modules',
'./ClientApp'
]
},
mode: `development`,
output: {
filename: '[name].js',
publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
},
module: {
rules: [
{
test: /\.tsx?$/, include: [path.resolve(__dirname, clientBundleOutputDir)],
use: [{
loader: 'babel-loader',
options: {
presets: ['#babel-preset-env', '#babel/preset-react', 'es2015', "#babel/typescript"],
plugins: ["#babel/proposal-class-properties",
"#babel/proposal-object-rest-spread",
"transform-eval",
'transform-es2015-arrow-functions']
}
}]
},
{ test: /\.json$/, loader: "json-loader" },
{ test: /\.tsx?$/, exclude: /(node_modules|bower_components)/, include: /ClientApp/, use: 'awesome-typescript-loader?silent=true' },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' },
{
test: /\.less$/, use: [{
loader: 'style-loader' // creates style nodes from JS strings
}, {
loader: 'css-loader' // translates CSS into CommonJS
}, {
loader: 'less-loader' // compiles Less to CSS
}]
},
{
test: /\.(woff|woff2|ttf|eot)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
}
}
]
}
]
}};
I am trying to use jQuery inside angular controller but I am getting above error
here is my package.json
{
"dependencies": {
"angular": "^1.6.2",
"angular-animate": "^1.6.8",
"angular-aria": "^1.6.8",
"angular-material": "^1.1.5",
"angular-messages": "^1.6.8",
"angular-ui-router": "1.0.0-beta.3",
"jquery": "^3.2.1"
},
"devDependencies": {
"#types/angular": "^1.6.6",
"#types/angular-mocks": "^1.5.9",
"#types/angular-ui-router": "^1.1.36",
"#types/jquery": "^2.0.40",
"angular-mocks": "^1.6.2",
"autoprefixer": "^6.7.3",
"babel-core": "^6.23.1",
"babel-eslint": "^7.1.1",
"babel-loader": "^6.3.2",
"babel-plugin-istanbul": "^4.0.0",
"babel-polyfill": "^6.23.0",
"babel-preset-es2015": "^6.22.0",
"browser-sync": "^2.18.8",
"browser-sync-spa": "^1.0.3",
"css-loader": "^0.26.1",
"del": "^2.2.2",
"es6-shim": "^0.35.3",
"eslint": "^3.19.0",
"eslint-config-angular": "^0.5.0",
"eslint-config-xo-space": "^0.15.0",
"eslint-loader": "^1.6.1",
"eslint-plugin-angular": "^1.6.1",
"eslint-plugin-babel": "^4.0.1",
"extract-text-webpack-plugin": "^2.0.0-rc.3",
"gulp": "gulpjs/gulp#4ed9a4a3275559c73a396eff7e1fde3824951ebb",
"gulp-angular-filesort": "^1.1.1",
"gulp-angular-templatecache": "^2.0.0",
"gulp-filter": "^5.0.0",
"gulp-htmlmin": "^3.0.0",
"gulp-hub": "frankwallis/gulp-hub#d461b9c700df9010d0a8694e4af1fb96d9f38bf4",
"gulp-insert": "^0.5.0",
"gulp-ng-annotate": "^2.0.0",
"gulp-sass": "^3.1.0",
"gulp-util": "^3.0.8",
"html-loader": "^0.4.4",
"html-webpack-plugin": "^2.28.0",
"jasmine": "^2.5.3",
"json-loader": "^0.5.4",
"karma": "^1.4.1",
"karma-angular-filesort": "^1.0.2",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.1.0",
"karma-junit-reporter": "^1.2.0",
"karma-ng-html2js-preprocessor": "^1.0.0",
"karma-phantomjs-launcher": "^1.0.2",
"karma-phantomjs-shim": "^1.4.0",
"karma-webpack": "^2.0.2",
"ng-annotate-loader": "^0.2.0",
"node-sass": "^4.5.0",
"phantomjs-prebuilt": "^2.1.14",
"postcss-loader": "^1.3.1",
"sass-loader": "^6.0.1",
"style-loader": "^0.13.1",
"webpack": "^2.2.1",
"webpack-fail-plugin": "^1.0.5"
},
"scripts": {
"build": "gulp",
"serve": "gulp serve",
"serve:dist": "gulp serve:dist",
"test": "gulp test",
"test:auto": "gulp test:auto"
},
"eslintConfig": {
"globals": {
"expect": true
},
"root": true,
"env": {
"browser": true,
"jasmine": true
},
"parser": "babel-eslint",
"extends": [
"xo-space/esnext"
]
}
}
and my webpack.config.js is
const webpack = require('webpack');
const conf = require('./gulp.conf');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FailPlugin = require('webpack-fail-plugin');
const autoprefixer = require('autoprefixer');
module.exports = {
module: {
loaders: [{
test: /\.json$/,
loaders: [
'json-loader'
]
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
enforce: 'pre'
},
{
test: /\.(css|scss)$/,
loaders: [
'style-loader',
'css-loader',
'sass-loader',
'postcss-loader'
]
},
{
test: /\.js$/,
exclude: /node_modules/,
loaders: [
'ng-annotate-loader',
'babel-loader'
]
},
{
test: /\.html$/,
loaders: [
'html-loader'
]
}
]
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
FailPlugin,
new HtmlWebpackPlugin({
template: conf.path.src('index.html')
}),
new webpack.LoaderOptionsPlugin({
options: {
postcss: () => [autoprefixer]
},
debug: true
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
}),
],
devtool: 'source-map',
output: {
path: path.join(process.cwd(), conf.paths.tmp),
filename: 'index.js'
},
entry: `./${conf.path.src('index')}`
};
in the above webpack config file I am setting jQuery to window object. But inside controller i am unable to access it. after doing the gulp serve, in the lint errors the above error is showing.