Why isn't babel-preset-react parsing my JSX? - reactjs

I get the following error when running webpack:
Error in ./src/index.jsx
Module parse failed: .../src/index.jsx Unexpected token (10:18)
You may need an appropriate loader to handle this file type.
I believe I have all the correct loaders set up, please tell me if I missed something.
package.json:
"dependencies": {
"isomorphic-fetch": "^2.2.1",
"koa": "^1.2.4",
"koa-ejs": "^3.0.0",
"koa-route": "^2.4.2",
"koa-router": "^5.4.0",
"koa-static": "^2.0.0",
"koa-webpack-dev-middleware": "^1.2.2",
"node-sass": "^3.10.1",
"react": "^15.3.2",
"react-dom": "^15.3.2",
"react-hot-loader": "^1.3.0",
"react-redux": "^4.4.5",
"react-router": "^2.8.1",
"redux": "^3.6.0",
"redux-thunk": "^2.1.0",
"sass-loader": "^4.0.2",
"style-loader": "^0.13.1",
"webpack": "^1.13.2"
},
"devDependencies": {
"babel-core": "^6.17.0",
"babel-eslint": "^7.0.0",
"babel-loader": "^6.2.6",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"babel-preset-react-hmre": "^1.1.1",
"css-loader": "^0.25.0",
"eslint": "^3.7.1",
"eslint-loader": "^1.5.0",
"eslint-plugin-react": "^6.4.1",
"koa-webpack-hot-middleware": "^1.0.3",
"react-hot-loader": "^1.3.0",
"redux-devtools": "^3.3.1",
"webpack-dev-server": "^1.16.2"
}
webpack.config.js:
const webpack = require('webpack');
const path = require('path');
const ROOT_PATH = path.resolve(__dirname);
module.exports = {
devtool: process.env.NODE_ENV === 'production' ? '' : 'source-map',
entry: [
'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000',
path.resolve(ROOT_PATH, 'src/index.jsx')
],
module: {
preLoaders: [{
test: /\.jsx?$/,
loaders: process.env.NODE_ENV === 'production' ? [] : ['eslint'],
include: path.resolve(ROOT_PATH, 'src/index.jsx')
}],
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015', 'stage-0', 'react'],
cacheDirectory: true,
env: {
development: {
presets: ['react-hmre']
}
}
},
include: './src'
},
{
test: /\.scss$/,
loaders: ['style', 'css', 'sass']
}]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
output: {
path: process.env.NODE_ENV === 'production'
? path.resolve(ROOT_PATH, 'dist')
: path.resolve(ROOT_PATH, 'build'),
publicPath: '/',
filename: 'bundle.js'
},
devServer: {
contentBase: path.resolve(ROOT_PATH, 'build'),
historyApiFallback: true,
hot: true,
inline: true,
progress: true
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
]
};
src/index.jsx:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App';
const main = () => {
const app = document.createElement('div');
document.body.appendChild(app);
ReactDOM.render(<App />, app);
};
main();
I have also tried without any presets using a .babelrc file:
{
"presets": ["es2015", "stage-0", "react"]
}
Running babel src/index.jsx does work as expected, so I think this is an issue with the webpack configuration.

My include path for the js(x) loader was wrong. Fixed using
include: path.resolve(ROOT_PATH, './src')
instead of
include: './src'

Related

export error while bundling #fluentui/react with webpack

I am getting webpack 5.25.0 compiled with 7 warnings in 6734 ms with version 7.167.0 and with v8.10.1 I was getting 1513 they were all same and something like this, instead of createElement there will be another react function like useEffect, with v8 it was taking 5 minutes to bundle in dev mode though with v7 took 10 sec.
export 'createElement' (imported as 'React') was not found in 'react'
Here is the webpack config
webpack.common.ts
import path from "path";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import HtmlWebpackPlugin from "html-webpack-plugin";
const isDevelopment = process.env.NODE_ENV !== "production";
const config = {
target: "web",
resolve: {
extensions: [".ts", ".tsx", ".js", ".json"],
modules: ["node_modules", "."],
alias: {
src: path.resolve(__dirname, "./src"),
// webpack was unable to understand the instance import
// and export, so we have explicitly tell it which comes
// from the node_modules
axios: path.resolve(__dirname, "./node_modules/axios"),
},
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "src", "index.html"),
}),
new ForkTsCheckerWebpackPlugin(),
new CleanWebpackPlugin(),
],
module: {
rules: [
{
// Include ts, tsx, js, and jsx files.
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
loader: "babel-loader",
options: {
// ... other options
plugins: [
// ... other plugins
isDevelopment && require.resolve("react-refresh/babel"),
].filter(Boolean),
},
},
{
test: /\.svg($|\?)/,
use: [
{
loader: "file-loader",
options: {
limit: 65000,
mimetype: "image/svg+xml",
name: "[name].[ext]",
},
},
],
},
{
test: /\.(png|jpg|gif)($|\?)/,
loader: "url-loader",
options: {
limit: 8192,
},
},
{
test: /\.(sa|sc|c)ss$/,
use: [
// Creates `style` nodes from JS strings
"style-loader",
// Translates CSS into CommonJS
"css-loader",
// Compiles Sass to CSS
"sass-loader",
],
},
],
},
};
module.exports = config;
webpack.dev.ts
const ReactRefreshWebpackPlugin = require("#pmmmwh/react-refresh-webpack-plugin");
import merge from "webpack-merge";
// #ts-ignore
import common from "./webpack.common";
const config = {
mode: "development",
output: {
publicPath: "/",
},
entry: ["./src/index"],
target: "web",
devtool: "eval-cheap-module-source-map",
plugins: [new ReactRefreshWebpackPlugin()],
devServer: {
clientLogLevel: "error",
port: 4444,
stats: "minimal",
hot: true,
historyApiFallback: true,
},
};
module.exports = merge(common, config);
pacakge.json
"dependencies": {
"#babel/core": "^7.13.10",
"#babel/plugin-proposal-class-properties": "^7.13.0",
"#babel/plugin-transform-typescript": "^7.13.0",
"#babel/preset-env": "^7.13.10",
"#babel/preset-react": "^7.12.13",
"#babel/preset-typescript": "^7.13.0",
"#fluentui/react": "^7.167.0",
"#pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
"#reduxjs/toolkit": "^1.5.1",
"#testing-library/react-hooks": "^5.1.1",
"#types/jest": "^26.0.20",
"#types/react": "^17.0.3",
"#types/react-dom": "^17.0.2",
"#types/react-redux": "^7.1.16",
"#types/react-router-dom": "^5.1.7",
"#types/redux-logger": "^3.0.8",
"#types/styled-components": "^5.1.9",
"#types/uglifyjs-webpack-plugin": "^1.1.1",
"#types/webpack-bundle-analyzer": "^4.4.0",
"#types/webpack-manifest-plugin": "^3.0.4",
"babel-loader": "^8.2.2",
"clean-webpack-plugin": "^3.0.0",
"css-loader": "^5.1.2",
"cypress": "^6.6.0",
"file-loader": "^6.2.0",
"fork-ts-checker-webpack-plugin": "^6.1.1",
"html-webpack-plugin": "^5.3.1",
"jest": "^26.6.3",
"lodash-es": "^4.17.21",
"normalize.css": "^8.0.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-redux": "^7.2.3",
"react-refresh": "^0.9.0",
"react-router-dom": "^5.2.0",
"react-spring": "^9.0.0",
"redux-logger": "^3.0.6",
"sass": "^1.32.8",
"sass-loader": "^11.0.1",
"style-loader": "^2.0.0",
"styled-components": "^5.2.1",
"ts-node": "^9.1.1",
"type-fest": "^0.21.3",
"typescript": "^4.2.3",
"uglifyjs-webpack-plugin": "^2.2.0",
"url-loader": "^4.1.1",
"webpack": "^5.25.0",
"webpack-bundle-analyzer": "^4.4.0",
"webpack-cli": "^4.5.0",
"webpack-dev-server": "^3.11.2",
"webpack-manifest-plugin": "^3.1.0",
"webpack-merge": "^5.7.3"
},
with v7 at least it is working with warnings and v8 there were webpack export errors too.
What I have tried so far
Removing the tsconfig, so it can use the default one.
allow synthetic default imports
removing react hot loader
Checked on CodeSand box with the same versions, everything working there so probably there is something's wrong with config.
Downgrading to React 16
Sample here
Somehow, there were multiple version/instance of React were in place, I assumed there is only as hooks were working correctly, aliasing the react with './node_modules/react' solved the issue for me

My react-admin bundle size is huge (860KB)

I already tried to configure various different optimization methods, but my react-admin bundle size stays huge, at 860KB.
What can I do about it? Is it normal? What can be a possible cause? I will post links with my webpack configs in a minute.
I don't think there's any clever way to do code-splitting for now. I have implemented few resources and they should always be used kind of together.
Link to my common webpack config:
https://pastebin.com/t6uMWiJ6
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
main: './src/components/index.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'static/js/[name].[contenthash:8].js'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
options: {
cacheDirectory: true,
cacheCompression: false,
babelrc: true
}
},
{ test: /\.json$/, loader: 'json-loader' },
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
exclude: [/\.(js|jsx)$/, /.html$/, /.css$/, /.json$/],
loader: 'file-loader',
options: {
name: 'static/media/[name].[contenthash:8].[ext]'
}
}
]
},
resolve: {
unsafeCache: true,
extensions: ['.js', '.jsx', '.json', '.css'],
alias: {
actions: path.resolve(__dirname, './src/actions'),
reducers: path.resolve(__dirname, './src/reducers'),
components: path.resolve(__dirname, './src/components'),
lib: path.resolve(__dirname, './src/components/_lib'),
styles: path.resolve(__dirname, './src/styles'),
config: path.resolve(__dirname, './src/config')
}
},
plugins: [
new HtmlWebpackPlugin({
template: './src/public/index.html',
favicon: './src/public/favicon.ico'
}),
new webpack.PrefetchPlugin('react'),
new webpack.PrefetchPlugin('react-dom')
],
optimization: {
usedExports: true
}
};
Here are my dependencies
{
"dependencies": {
"#babel/runtime": "^7.9.2",
"#material-ui/core": "^4.9.13",
"#material-ui/icons": "^4.9.1",
"#material-ui/pickers": "next",
"connected-react-router": "^6.8.0",
"final-form": "^4.19.1",
"jwt-decode": "^2.2.0",
"moment": "^2.25.3",
"prop-types": "^15.7.2",
"ra-core": "^3.5.0",
"ra-data-simple-rest": "^3.2.2",
"react": "^16.12.0",
"react-admin": "^3.1.1",
"react-dom": "^16.12.0",
"react-final-form": "^6.4.0",
"react-redux": "^7.2.0",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"redux": "^4.0.5",
"redux-saga": "^1.1.3"
},
"devDependencies": {
"#babel/core": "^7.9.6",
"#babel/plugin-syntax-dynamic-import": "^7.8.3",
"#babel/plugin-transform-runtime": "^7.9.0",
"#babel/preset-env": "^7.9.5",
"#babel/preset-react": "^7.9.4",
"babel-loader": "^8.1.0",
"css-loader": "^3.5.2",
"file-loader": "^6.0.0",
"html-webpack-plugin": "^4.3.0",
"style-loader": "^1.2.1",
"webpack": "next",
"webpack-bundle-analyzer": "^3.7.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.11.0",
"webpack-manifest-plugin": "^2.2.0",
"webpack-merge": "^4.2.2"
},
"peerDependencies": {
"history": "^4.10.1",
"immutable": "^4.0.0-rc.12",
"seamless-immutable": "^73.1.4"
},
"sideEffects": [
"*.css"
]
}
Tree shaking is probably what you need to look at. See https://webpack.js.org/guides/tree-shaking/
Note, as they say above, the way you import your modules in your source code is lso important here.
In essence though, it should enable webpack to just bundle the parts of npm packages that are needed.

webpack issue in react native - 'Plugin/Preset files are not allowed to export objects, only functions.'

There was lot of answers for this issue which are outdated i guess because none of the solutions worked for me.
Scenario:
I am using react-native-web and react-native for web and mobile apps. For react-native-web, I need to bundle the js in order to make react-native-web work since I started using react-router-native.
Without react-router-native, the webpack bundled the js perfectly, but when adding it, it throws error.
ERROR in ../index.js
Module build failed (from ../node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/name/Documents/rn/node_modules/babel-preset-es2016/lib/index.js
at createDescriptor (/Users/name/Documents/rn/node_modules/#babel/core/lib/config/config-descriptors.js:178:11)
at items.map (/Users/name/Documents/rn/node_modules/#babel/core/lib/config/config-descriptors.js:109:50)
at Array.map (<anonymous>)
at createDescriptors (/Users/name/Documents/rn/node_modules/#babel/core/lib/config/config-descriptors.js:109:29)
at createPresetDescriptors (/Users/name/Documents/rn/node_modules/#babel/core/lib/config/config-descriptors.js:101:10)
at passPerPreset (/Users/name/Documents/rn/node_modules/#babel/core/lib/config/config-descriptors.js:58:104)
at cachedFunction (/Users/name/Documents/rn/node_modules/#babel/core/lib/config/caching.js:62:27)
at cachedFunction.next (<anonymous>)
at evaluateSync (/Users/name/Documents/rn/node_modules/gensync/index.js:244:28)
at sync (/Users/name/Documents/rn/node_modules/gensync/index.js:84:14)
babel.config.js:
module.exports = {
presets: [
'#babel/preset-env',
'#babel/preset-react',
'module:metro-react-native-babel-preset'
],
plugins: [
'#babel/plugin-proposal-class-properties'
]
};
webpack.config.js:
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const rootDir = path.join(__dirname, '..');
const webpackEnv = process.env.NODE_ENV || 'development';
module.exports = {
mode: webpackEnv,
entry: {
app: path.join(rootDir, './index.js'),
},
output: {
path: path.resolve(rootDir, 'dist'),
filename: 'app-[hash].bundle.js',
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.(tsx|ts|jsx|js|mjs)$/,
exclude: /node_modules/,
loader: 'babel-loader',
"query": {
"presets": ["#babel/preset-env", "#babel/preset-react", "es2016"],
}
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, './index.html'),
}),
new webpack.HotModuleReplacementPlugin(),
],
resolve: {
extensions: [
'.web.tsx',
'.web.ts',
'.tsx',
'.ts',
'.web.jsx',
'.web.js',
'.jsx',
'.js',
],
alias: Object.assign({
'react-native$': 'react-native-web',
}),
},
};
Package.json:
"dependencies": {
"babel-preset-es2015": "^6.24.1",
"react": "16.9.0",
"react-circular-progressbar": "^2.0.3",
"react-dom": "^16.12.0",
"react-native": "0.61.5",
"react-native-progress-circle": "^2.1.0",
"react-native-web": "^0.12.0-rc.1",
"react-redux": "^7.1.3",
"react-router-native": "^5.1.2",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"#babel/core": "^7.8.3",
"#babel/preset-env": "^7.8.3",
"#babel/preset-react": "^7.8.3",
"#babel/runtime": "^7.8.3",
"#react-native-community/eslint-config": "^0.0.6",
"#types/react": "^16.9.17",
"#types/react-native": "^0.60.31",
"babel-jest": "^24.9.0",
"babel-loader": "^8.0.6",
"babel-preset-es2016": "^6.24.1",
"eslint": "^6.8.0",
"html-webpack-plugin": "^3.2.0",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.56.4",
"react-native-typescript-transformer": "^1.2.13",
"react-test-renderer": "16.9.0",
"ts-loader": "^6.2.1",
"typescript": "^3.7.5",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.10.1"
},
Thanks for the help.

Can't resolve 'react-hot-loader/webpack'

I've been stuck with this for a while trying to install and update. Finally, all the npm packages are in the latest version. Could you please let me know how I could get past this blocking error?
[ERROR] ERROR in multi react-hot-loader/patch event-source-polyfill webpack-hot-middleware/client?path=__webpack_hmr&dynamicPublicPath=true ./ClientApp/boot.tsx
Module not found: Error: Can't resolve 'react-hot-loader/webpack' in '...'
# multi react-hot-loader/patch event-source-polyfill webpack-hot-middleware/client?path=__webpack_hmr&dynamicPublicPath=true ./ClientApp/boot.tsx
Here's my webpack.config.js:
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const bundleOutputDir = './wwwroot/dist';
module.exports = (env) => {
const isDevBuild = !(env && env.prod);
return [{
stats: { modules: false },
entry: { 'main': './ClientApp/boot.tsx' },
resolve: { extensions: ['.js', '.jsx', '.ts', '.tsx'] },
output: {
path: path.join(__dirname, bundleOutputDir),
filename: '[name].js',
publicPath: 'dist/'
},
module: {
rules: [
{ test: /\.tsx?$/, include: /ClientApp/, use: 'awesome-typescript-loader?silent=true' },
{ test: /\.css$/, use: isDevBuild ? ['style-loader', 'css-loader'] : ExtractTextPlugin.extract({ use: 'css-loader?minimize' }) },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' },
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "url-loader"
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "url-loader"
}
]
},
plugins: [
new CheckerPlugin(),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./wwwroot/dist/vendor-manifest.json')
})
].concat(isDevBuild ? [
// Plugins that apply in development builds only
new webpack.SourceMapDevToolPlugin({
filename: '[file].map', // Remove this line if you prefer inline source maps
moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
})
] : [
// Plugins that apply in production builds only
new webpack.optimize.UglifyJsPlugin(),
new ExtractTextPlugin('site.css')
])
}];
};
Here is the package.json so that the versions of the packages that I'm using are shown below:
{
"name": "MyProject",
"private": true,
"version": "0.0.0",
"devDependencies": {
"#types/history": "4.6.2",
"#types/react": "^16.4.1",
"#types/react-dom": "16.0.6",
"#types/react-hot-loader": "4.1.0",
"#types/react-router": "4.0.27",
"#types/react-router-dom": "4.2.7",
"#types/react-table": "^6.7.11",
"#types/webpack-env": "1.13.6",
"aspnet-webpack": "^3.0.0",
"aspnet-webpack-react": "^3.0.0",
"awesome-typescript-loader": "5.2.0",
"bootstrap": "4.1.1",
"css-loader": "0.28.11",
"event-source-polyfill": "0.0.12",
"extract-text-webpack-plugin": "3.0.2",
"file-loader": "1.1.11",
"isomorphic-fetch": "2.2.1",
"jquery": "3.3.1",
"json-loader": "0.5.7",
"react": "16.4.1",
"react-dom": "^16.4.1",
"react-hot-loader": "^4.3.3",
"react-router-dom": "4.3.1",
"style-loader": "0.21.0",
"typescript": "2.9.2",
"url-loader": "1.0.1",
"webpack": "^4.12.2",
"webpack-dev-middleware": "^3.1.3",
"webpack-dev-server": "^3.1.4",
"webpack-hot-middleware": "^2.22.2"
},
"dependencies": {
"#types/react-fontawesome": "^1.6.3",
"ajv": "^6.5.1",
"classnames": "^2.2.6",
"font-awesome": "^4.7.0",
"get-latest": "^0.1.0",
"latest-version": "^4.0.0",
"npm": "^6.1.0",
"npm-install-peers": "^1.2.1",
"popper.js": "^1.14.3",
"react-table": "^6.8.6",
"update-all-packages": "^1.0.2"
}
}

Unable to configure Jest in my React App

I'm just starting with tests right now, trying to set up the Jest with my project, but it has been painful.. I am trying to do the React App tutorial, with the Webpack Tutorial, and I'm facing if this error:
C:\Users\myuser\Desktop\myapp\__tests__\Link.test.js:2
import React from 'react';
^^^^^^
SyntaxError: Unexpected token import
at transformAndBuildScript (node_modules\jest-runtime\build\transform.js:320:12)
I'm using Node v7.5.0 and Webpack 2. I installed all the necessary dependencies and I also tried to sort with jest configuration, but it didn't sort my problem.
My package.json looks like this:
{
"name": "myapp",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"jest": {
"modulePaths": ["<rootDir>/src/"],
"moduleDirectories": ["node_modules"],
"transform": {
"^.+\\.jsx?$": "babel-jest"
},
"transformIgnorePatterns": [
"<rootDir>/(node_modules)/"
]
},
"scripts": {
"start": "webpack-dev-server --progress --watch",
"build": "webpack --progress",
"test": "jest --verbose"
},
"devDependencies": {
"babel-core": "^6.22.1",
"babel-eslint": "^7.1.1",
"babel-jest": "^18.0.0",
"babel-loader": "^6.2.10",
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.0",
"babel-polyfill": "^6.22.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.22.0",
"babel-preset-stage-2": "^6.22.0",
"css-loader": "^0.26.1",
"eslint": "^3.15.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-import-resolver-webpack": "^0.8.1",
"eslint-loader": "^1.6.1",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jest": "^1.0.2",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.9.0",
"extract-text-webpack-plugin": "^1.0.1",
"html-webpack-plugin": "^2.28.0",
"jest": "^18.1.0",
"jest-cli": "^19.0.2",
"node-sass": "^4.5.0",
"react-hot-loader": "3.0.0-beta.6",
"react-test-renderer": "^15.4.2",
"sass-loader": "^5.0.1",
"style-loader": "^0.13.1",
"url-loader": "^0.5.8",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.3.0"
},
"dependencies": {
"chart.js": "^2.5.0",
"classnames": "^2.2.5",
"file-loader": "^0.11.1",
"flexboxgrid": "^6.3.1",
"google-map-react": "^0.22.3",
"intl": "^1.2.5",
"intl-locales-supported": "^1.0.0",
"lodash": "^4.17.4",
"material-ui": "^0.17.0",
"moment": "^2.17.1",
"node-schedule": "^1.2.1",
"normalize.css": "^5.0.0",
"re-base": "^2.6.0",
"react": "^15.4.2",
"react-chartjs-2": "^2.0.5",
"react-dom": "^15.4.2",
"react-flexbox-grid": "^0.10.2",
"react-router-dom": "^4.0.0",
"react-scrollbar": "^0.5.1",
"react-tap-event-plugin": "^2.0.1",
"webpack": "^2.2.1"
}
}
My .babelrc file looks like this:
{
"presets": [
["es2015", {"modules": false}],
"stage-2",
"react"
],
"plugins": [
"react-hot-loader/babel"
],
"env": {
"test": {
"plugins": ["transform-es2015-modules-commonjs"]
}
}
}
I also set the environment to test, but it didn't make any effect.
My Webpack file looks like this:
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const plugins = [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, './src/index.html'),
inject: true,
favicon: path.resolve(__dirname, './src/images/favicon.ico'),
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('dev'),
},
}),
];
module.exports = {
devtool: 'cheap-eval-source-map',
entry: [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./index.jsx',
],
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'public'),
publicPath: '/',
},
context: path.resolve(__dirname, 'src'),
resolve: {
modules: [path.resolve(__dirname, './src'), path.resolve(__dirname, './node_modules')],
extensions: ['.js', '.jsx'],
},
devServer: {
hot: true,
port: 3000,
contentBase: path.resolve(__dirname, 'public'),
historyApiFallback: true,
publicPath: '/',
},
module: {
rules: [
{
test: /(\.js|\.jsx)$/,
enforce: 'pre',
exclude: /node_modules/,
use: {
loader: 'eslint-loader',
options: {
failOnWarning: false,
failOnError: false,
},
},
},
{
test: /(\.js|\.jsx)$/,
use: ['babel-loader'],
exclude: /node_modules/,
},
{
test: /(\.scss|\.css)$/,
use: [
{ loader: 'style-loader' },
{
loader: 'css-loader',
options: {
modules: true,
},
},
{ loader: 'sass-loader' },
],
},
{
test: /\.(png|jpg|)$/,
use: ['url-loader?limit=200000'],
},
],
},
plugins: plugins,
};
Can someone help me with this issue? Thanks!

Resources