React app failed to load config "airbnb" in deploying to heroku - reactjs

I failed to deploy my create react app to heroku. Error log is below.
-----> Build
Running build (yarn)
yarn run v1.22.10
$ react-scripts build
Creating an optimized production build...
Failed to compile.
Failed to load config "airbnb" to extend from.
Referenced from: /tmp/build_49ca30fd/.eslintrc.js
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
Some possible problems:
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed
This is my eslint.js.
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
'plugin:react/recommended',
'airbnb',
'airbnb/hooks',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:#typescript-eslint/recommended',
'plugin:#typescript-eslint/recommended-requiring-type-checking',
'prettier',
],
parser: '#typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 12,
project: './tsconfig.eslint.json',
sourceType: 'module',
tsconfigRootDir: __dirname,
},
plugins: [
'react',
'#typescript-eslint',
'import',
'jsx-a11y',
'react-hooks',
'prettier',
],
root: true,
rules: {
'import/no-cycle': 'off',
'no-use-before-define': 'off',
'no-alert': 'off',
'#typescript-eslint/no-use-before-define': ['error'],
'lines-between-class-members': [
'error',
'always',
{
exceptAfterSingleLine: true,
},
],
'no-void': [
'error',
{
allowAsStatement: true,
},
],
'padding-line-between-statements': [
'error',
{
blankLine: 'always',
prev: '*',
next: 'return',
},
],
'#typescript-eslint/no-unused-vars': [
'warn',
{
vars: 'all',
args: 'after-used',
argsIgnorePattern: '_',
ignoreRestSiblings: false,
varsIgnorePattern: '_',
},
],
'#typescript-eslint/no-unsafe-member-access': ['warn'],
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
},
],
'react/jsx-filename-extension': [
'error',
{
extensions: ['.jsx', '.tsx'],
},
],
'react/jsx-props-no-spreading': ['off'],
'lines-between-class-members': [
'error',
'always',
{
exceptAfterSingleLine: true,
},
],
},
overrides: [
{
files: ['*.tsx'],
rules: {
'react/prop-types': 'off',
},
},
],
settings: {
'import/resolver': {
node: {
paths: ['src'],
},
},
},
}
I use style guide of airbnb with eslint and prettier in my app. I installed them to devDependencies. My pacakage.json is below.
{
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^1.2.35",
"#fortawesome/free-solid-svg-icons": "^5.15.3",
"#fortawesome/react-fontawesome": "^0.1.14",
"#hookform/resolvers": "^2.4.0",
"#loadable/component": "^5.14.1",
"#material-ui/core": "^4.11.4",
"#material-ui/icons": "^4.11.2",
"#material-ui/lab": "^4.0.0-alpha.58",
"#types/date-fns": "^2.6.0",
"#types/node": "^15.0.1",
"#types/react": "^17.0.4",
"#types/react-dom": "^17.0.3",
"#types/styled-components": "^5.1.9",
"axios": "^0.21.1",
"camelcase-keys": "^6.2.2",
"date-fns": "^2.21.1",
"express": "^4.17.1",
"express-favicon": "^2.0.1",
"file-saver": "^2.0.5",
"firebase": "^8.4.3",
"heroku-ssl-redirect": "^0.1.1",
"little-state-machine": "^3.1.4",
"path": "^0.12.7",
"qs": "^6.10.1",
"react": "^16.13.1",
"react-circular-progressbar": "^2.0.4",
"react-devtools": "^4.13.0",
"react-dom": "^16.13.1",
"react-hook-form": "^7.3.5",
"react-media": "^1.10.0",
"react-responsive": "^8.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"react-sortablejs": "^6.0.0",
"sanitize-html": "^2.3.3",
"snakecase-keys": "^4.0.1",
"sortablejs": "^1.13.0",
"source-map-explorer": "^2.5.2",
"styled-components": "^5.2.3",
"styled-media-query": "^2.1.2",
"typescript": "~4.2.4",
"typesync": "^0.8.0",
"uuid": "^8.3.2",
"yup": "^0.32.9"
},
"devDependencies": {
"#types/eslint": "^7.2.10",
"#types/eslint-plugin-prettier": "^3.1.0",
"#types/express": "^4.17.11",
"#types/file-saver": "^2.0.2",
"#types/loadable__component": "^5.13.3",
"#types/prettier": "2.2.3",
"#types/qs": "^6.9.6",
"#types/react-devtools": "^3.6.0",
"#types/react-responsive": "^8.0.2",
"#types/react-router-dom": "^5.1.7",
"#types/sanitize-html": "^2.3.1",
"#types/snakecase-keys": "^2.1.0",
"#types/sortablejs": "^1.10.6",
"#types/uuid": "^8.3.0",
"#types/yup": "^0.29.11",
"#typescript-eslint/eslint-plugin": "^4.22.0",
"#typescript-eslint/parser": "^4.22.0",
"dotenv": "^8.2.0",
"eslint": "^7.2.0",
"eslint-config-airbnb": "18.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^1.7.0",
"prettier": "2.2.1",
}
}
When heroku deployed an app, heroku remove devDependencies. I think this is the reason. I tried to set YARN_PRODUCTION env as false. Then, I succeeded.
But, because devDependencies is installed, bundle size is bigger. I want to avoid it.
How do I handle devDependencies in deploying app using eslint and prettier to heroku?

Just stumbled on this issue and couldn't resolve it after an entire day knocking about the web. Had to disable eslint-webpack-plugin in production builds:
create file .env.production
open file and add DISABLE_ESLINT_PLUGIN=true
During CI you can still run yarn lint or whatever your linting script with no problems and avoid this webpack issue that only happens on yarn build
Sources:
GitHub Issue
CRA Advanced Configuration
CRA .env files

Heroku supports custom build script, in which you can set the environment variable directly:
"scripts": {
...
"build": "react-scripts build",
"heroku-postbuild": "DISABLE_ESLINT_PLUGIN=true react-scripts build"
},
piouson's answer does the job, however i find it cleaner to use the following solution as it is (at least I believe) Heroku-specific problem and .env.production file could influence other potential production servers.

Related

React does not have hot/live reload, how to set it up?

I recently joined a company that works with react (classes) and typescript, I was flabbergasted when I knew that the react they are using does not hot/live reload on changes (CSS, state, or any change), what happens on changes is webpack recompiles (takes around 25 seconds) and to see changes I should reload the page which is slowing down the development experience greatly.
Talking to the manager it was decided that we do a migration to a new create react app gradually as there is lots of code and redundancy and we want to use functional react hooks (which will take years maybe as the app is big) but until then I want to resolve the hot reload issue.
I believe the react app a long time ago was not started with creat-react-app or something.
Just to mention I have 1.5 yrs experience in the industry so config stuff is still new to me and am just doing this for my learning benefits and to improve the team experience, it's not really an assigned task to do.
Below are our package.json, webpack file, and index file. Please let me know if you need to see anything else.
Package.json:
{
"name": "web-front-end",
"version": "1.22.19",
"description": "HTML5 implementation of the <our company name>. Written in Typescript, compiled to JavaScript, bundled with Webpack, executing on NodeJS, using React, adopting FLUX patterns.",
"private": true,
"scripts": {
"babel": "babel built/client/js/client.js -o built/client/js/client.js",
"clean": "rm -rf node_modules && rm -rf built && rm -rf coverage && echo 'clean complete'",
"reset": "yarn clean && yarn cache clean && yarn install --frozen-lockfile",
"compile": "yarn compile-client && yarn compile-server && yarn babel",
"debug-client": "NODE_ENV=debug webpack --config webpack.dev.js && echo 'client compile complete'",
"compile-client": "NODE_ENV=production webpack --config webpack.prod.js && echo 'production client compile complete'",
"compile-client-dev": "NODE_ENV=development webpack --config webpack.dev.js && echo 'development client compile complete'",
"compile-client-dev-watch": "NODE_ENV=development webpack --config webpack.dev-watch.js",
"compile-server": "tsc -p src/server && echo 'server compile complete'",
"compile-client-watch": "NODE_ENV=development webpack --config webpack.dev-watch.js",
"compile-server-watch": "tsc -p src/server --watch",
"validate": "yarn --ignore-engines && tslint './src/**/*.{ts,tsx}' './test/**/*.{ts,tsx}' && echo 'validate complete'",
"start-server": "node ./built/server/ServerApp.js",
"test": "tslint --project test && tslint --project src/app && tsc -p test --jsx react && node ./node_modules/jest/bin/jest.js --config=jest.test.config.json --coverage --verbose",
"lint-fix": "tslint --fix --project src && tslint --fix --project test",
"prepare": "patch-package"
},
"dependencies": {
"#emotion/react": "^11.9.3",
"#emotion/styled": "^11.9.3",
"#mui/icons-material": "^5.8.4",
"#mui/material": "^5.8.4",
"#mui/styles": "^5.8.4",
"#stripe/stripe-js": "1.11.0",
"assert": "^2.0.0",
"axios": "^0.27.2",
"blob-stream": "0.1.3",
"buffer": "^6.0.3",
"compression": "1.7.3",
"compression-webpack-plugin": "^10.0.0",
"connected-react-router": "^6.9.2",
"cors": "2.8.4",
"device-uuid": "1.0.4",
"dotenv": "6.0.0",
"express": "4.16.3",
"file-saver": "^2.0.5",
"html-to-image": "^1.10.8",
"https-browserify": "^1.0.0",
"js-cookie": "2.2.0",
"node-zip": "1.1.1",
"path-to-regexp": "2.4.0",
"pug": "2.0.3",
"query-string": "6.1.0",
"react": "17.0.0",
"react-copy-to-clipboard": "5.0.1",
"react-dom": "^17.0.2",
"react-form-validator-core": "0.4.4",
"react-hook-form": "^7.36.0",
"react-inlinesvg": "2.3.0",
"react-jss": "8.5.1",
"react-lazy-load": "3.0.13",
"react-markdown": "4.0.4",
"react-material-ui-form-validator": "^3.0.1",
"react-player": "1.14.2",
"react-redux": "^7.2.6",
"react-router": "5.2.1",
"react-router-dom": "5.3.0",
"react-share": "2.4.0",
"react-speech-recognition": "^3.10.0",
"react-stripe-elements": "2.0.1",
"react-svgmt": "^1.2.0",
"react-virtualized": "9.22.3",
"react-youtube": "7.9.0",
"recompose": "0.27.1",
"rect": "1.2.1",
"redux": "4.0.0",
"redux-thunk": "2.3.0",
"regenerator-runtime": "^0.13.9",
"shortid": "2.2.15",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"svg-to-pdfkit": "0.1.7",
"url": "^0.11.0",
"utf8": "3.0.0"
},
"devDependencies": {
"#babel/cli": "^7.17.6",
"#babel/core": "^7.17.8",
"#babel/types": "^7.17.0",
"#types/blob-stream": "0.1.29",
"#types/code": "4.0.4",
"#types/detect-browser": "3.0.0",
"#types/jest": "25.2.3",
"#types/js-cookie": "2.2.1",
"#types/lab": "11.1.0",
"#types/react": "17.0.14",
"#types/react-dom": "17.0.14",
"#types/react-inlinesvg": "1.0.0",
"#types/react-redux": "^7.1.20",
"#types/react-router": "4.4.5",
"#types/react-virtualized": "9.21.18",
"#types/shortid": "0.0.29",
"#types/utf8": "2.1.6",
"awesome-typescript-loader": "3.4.1",
"copy-webpack-plugin": "4.5.1",
"detect-browser": "3.0.1",
"fork-ts-checker-webpack-plugin": "^7.2.13",
"jest": "^27.5.1",
"patch-package": "6.1.2",
"postinstall-postinstall": "2.0.0",
"process": "^0.11.10",
"source-map-loader": "0.2.3",
"source-map-support": "0.4.18",
"ts-jest": "27.1.2",
"ts-loader": "^9.3.1",
"ts-mockito": "2.3.0",
"ts-node": "^10.8.1",
"tslint": "^6.0.1",
"tslint-eslint-rules": "5.4.0",
"tslint-react": "^5.0.0",
"typescript": "4.1.5",
"webpack": "^5.73.0",
"webpack-bundle-analyzer": "^3.0.3",
"webpack-cli": "^4.10.0",
"webpack-merge": "^5.8.0"
},
"resolutions": {
"#types/prop-types": "15.7.5",
"#types/unist": "2.0.0",
"#types/react-transition-group": "2.0.8",
"#types/react": "17.0.14",
"#types/react-dom": "17.0.14"
},
"repository": {
"type": "git",
"url": "our repo link"
},
"author": "our company name",
"license": "MIT",
}
Webpack.common.js:
const path = require("path");
const webpack = require('webpack');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
module.exports = {
entry: "./src/app/Main.ts",
cache: false,
optimization: {
providedExports: true,
usedExports: true,
removeAvailableModules: true,
removeEmptyChunks: true,
mergeDuplicateChunks: true,
chunkIds: 'named',
},
plugins: [
new webpack.ProvidePlugin({process: "process/browser"}),
new ForkTsCheckerWebpackPlugin(
{
typescript: {
configFile: './src/app/tsconfig.json'
}
}),
],
module: {
rules: [
{
test: /\.tsx?$/i,
loader: "ts-loader",
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: "asset/resource",
generator: {
filename: 'assets/[hash][ext]',
},
},
],
},
resolve: {
alias: {
core: path.join(__dirname, "src", "core"),
client: path.join(__dirname, "src", "client"),
server: path.join(__dirname, "src", "server"),
'<our company name>-typescript-common': path.resolve(__dirname, 'node_modules/<our company name>-typescript-common/'),
},
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js", ".jsx"],
fallback: {
"util": require.resolve('util'),
"os": false,
"fs": false,
"path": false,
"zlib": false,
"buffer": require.resolve('buffer'),
"http": require.resolve('stream-http'),
"https": require.resolve('https-browserify'),
"url": require.resolve('url'),
"stream": require.resolve('stream-browserify'),
},
},
output: {
path: path.resolve(__dirname, "built"),
filename: "client/js/client.js",
clean: true,
},
};
index.js (called Main.ts on our codebase)
import { render } from 'react-dom';
import { AppWrapper } from './view/App/AppWrapper';
declare var window: any;
class CompanyName {
constructor() {
window.dataLayer = window.dataLayer || [];
window._hsq = window._hsq || [];
const rootHtmlElement = document.body.appendChild(document.createElement('div'));
render(new AppWrapper({
lang: window.appConfig.LANGUAGE,
appConfig: window.appConfig,
startupTimestamp: window.sts}).render(), rootHtmlElement);
}
}
// tslint:disable-next-line:no-unused-expression
new CompanyName();
webpack.dev-watch.js:
const { merge } = require("webpack-merge");
const common = require("./webpack.dev.js");
const path = require('path');
module.exports = merge(common, {
watch: true,
optimization: {
minimize: false,
mangleExports: false,
mangleWasmImports: false
},
watchOptions: {
ignored: [
path.posix.resolve(__dirname, './node_modules'),
path.posix.resolve(__dirname, './rfg'),
path.posix.resolve(__dirname, './patches'),
path.posix.resolve(__dirname, './built'),
],
poll: 1500,
aggregateTimeout: 1000,
},
});
I would be grateful if you provide any explanations, explanatory links or videos in your answers so I can learn more.
Thanks.

How to fix Vite build / parser error "Unexpected token" in third party dependencies?

I'm trying to create a production build of my React application with Vite. When I run the npm run dev command, the app will start and seems to work as it should, but during the build I always get these kind of parser errors by some third party dependencies, telling that it includes an unexpected token.
Am I missing something in my config file or what could it be?
❯ npm run build
> project build
> tsc && vite build
vite v2.9.12 building for production...
✓ 4 modules transformed.
[commonjs] Unexpected token (1:20) in /Users/../node_modules/react-router-dom/index.js
file: /Users/../node_modules/react-router-dom/index.js:1:20
1: /**
^
2: * React Router DOM v6.3.0
3: *
error during build:
SyntaxError: Unexpected token (1:20) in /Users/../node_modules/react-router-dom/index.js
at Parser.pp$4.raise (/Users/../node_modules/rollup/dist/shared/rollup.js:19740:13)
at Parser.pp$9.unexpected (/Users/../node_modules/rollup/dist/shared/rollup.js:17034:8)
at Parser.pp$5.parseIdent (/Users/../node_modules/rollup/dist/shared/rollup.js:19671:10)
at Parser.pp$8.parseImportSpecifiers (/Users/../node_modules/rollup/dist/shared/rollup.js:18117:27)
at Parser.pp$8.parseImport (/Users/../node_modules/rollup/dist/shared/rollup.js:18078:28)
at Parser.pp$8.parseStatement (/Users/../rollup/dist/shared/rollup.js:17210:49)
at Parser.pp$8.parseTopLevel (/Users/../node_modules/rollup/dist/shared/rollup.js:17091:21)
at Parser.parse (/Users/../node_modules/rollup/dist/shared/rollup.js:16863:15)
at Function.parse (/Users/../node_modules/rollup/dist/shared/rollup.js:16913:35)
at Graph.contextParse (/Users/m../node_modules/rollup/dist/shared/rollup.js:23017:38)
The project was initialized with React and TypeScript. I had to configure polyfills for several libs that required node dependencies. The vite.config.ts looks like this:
import { defineConfig } from 'vite';
import react from '#vitejs/plugin-react';
import * as path from 'path';
import { NodeGlobalsPolyfillPlugin } from '#esbuild-plugins/node-globals-polyfill';
import { NodeModulesPolyfillPlugin } from '#esbuild-plugins/node-modules-polyfill';
import polyfillNode from 'rollup-plugin-polyfill-node';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), polyfillNode()],
resolve: {
alias: {
'#': path.resolve(__dirname, 'src'),
util: 'rollup-plugin-node-polyfills/polyfills/util',
events: 'rollup-plugin-node-polyfills/polyfills/events',
stream: 'rollup-plugin-node-polyfills/polyfills/stream',
path: 'rollup-plugin-node-polyfills/polyfills/path',
zlib: 'rollup-plugin-node-polyfills/polyfills/zlib',
},
},
define: {
// By default, Vite doesn't include shims for NodeJS/
// necessary for segment analytics lib to work
global: {},
process: { env: { HOME: './src' } },
},
server: {
host: true,
port: 5001,
hmr: { host: 'localhost' },
proxy: {
'/api': {
target: 'http://localhost:3001',
changeOrigin: true,
secure: false,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis',
},
// Enable esbuild polyfill plugins
plugins: [
NodeGlobalsPolyfillPlugin({
process: true,
buffer: true,
}),
NodeModulesPolyfillPlugin(),
],
},
},
build: {
commonjsOptions: {
transformMixedEsModules: true,
},
rollupOptions: {
output: {
dir: 'output',
format: 'cjs',
},
plugins: [
// Enable rollup polyfills plugin
// used during production bundling
polyfillNode(),
],
},
},
});
Here is the package.json:
{
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"#emotion/react": "^11.9.3",
"#emotion/styled": "^11.9.3",
"#esbuild-plugins/node-globals-polyfill": "^0.1.1",
"#esbuild-plugins/node-modules-polyfill": "^0.1.4",
"#mui/icons-material": "^5.8.4",
"#mui/lab": "^5.0.0-alpha.87",
"#mui/material": "^5.8.5",
"#mui/x-date-pickers": "^5.0.0-alpha.6",
"#react-pdf/renderer": "^2.2.0",
"#types/luxon": "^2.3.2",
"amazon-cognito-identity-js": "^5.2.9",
"axios": "^0.27.2",
"draft-js": "^0.11.7",
"events": "^3.3.0",
"luxon": "^2.4.0",
"preval.macro": "^5.0.0",
"react": "^18.0.0",
"react-beautiful-dnd": "^13.1.0",
"react-dom": "^18.0.0",
"react-draft-wysiwyg": "^1.14.7",
"react-dropzone": "^14.2.1",
"react-redux": "^8.0.2",
"react-router-dom": "^6.3.0",
"redux-logger": "^3.0.6",
"rollup-plugin-polyfill-node": "^0.9.0",
"stream": "^0.0.2",
"util": "^0.12.4",
"uuid": "^8.3.2",
"zlib": "^1.0.5"
},
"devDependencies": {
"#reduxjs/toolkit": "^1.8.2",
"#rollup/plugin-commonjs": "^22.0.1",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.3.0",
"#types/draft-js": "^0.11.9",
"#types/jest": "^28.1.3",
"#types/node": "^18.0.0",
"#types/preval.macro": "^3.0.0",
"#types/react": "^18.0.0",
"#types/react-beautiful-dnd": "^13.1.2",
"#types/react-dom": "^18.0.0",
"#types/react-draft-wysiwyg": "^1.13.4",
"#types/react-redux": "^7.1.24",
"#types/react-router-dom": "^5.3.3",
"#types/redux-logger": "^3.0.9",
"#types/uuid": "^8.3.4",
"#vitejs/plugin-react": "^1.3.0",
"jest": "^28.1.1",
"typescript": "^4.6.3",
"vite": "^2.9.9"
}
}
I think you should use global: '({})' rather than global: {} in vite.config.ts
Check out the link below for more details.
https://github.com/vitejs/vite/issues/8909

Problem Bundling React Typescript Project with Rollup

I have a Typescript React Project and bundle it using rollup. My config files are:
tsconfig.json
{
"compilerOptions": {
"outDir": "dist",
"noImplicitAny": true,
"module": "esnext",
"target" : "es6",
"lib": ["es6", "es7", "dom"],
"jsx": "react",
"allowJs": true,
"removeComments": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "Node"
},
"include": ["src/**/**/*"],
"exclude": ["node_modules/**", "**/*.spec.ts", "dist"]
}
rollup.config.js
import typescript from "rollup-plugin-typescript";
import commonjs from "rollup-plugin-commonjs";
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import nodeResolve from "rollup-plugin-node-resolve";
import postcss from 'rollup-plugin-postcss'
// import babel from 'rollup-plugin-babel';
import pkg from "./package.json";
const globals = {
react: 'React',
'react-dom': 'ReactDom',
'react-datepicker2': 'DatePicker',
};
const plugins = [
peerDepsExternal(),
nodeResolve({
mainFields: ['module'],
extensions: ['.ts', '.tsx']
}),
commonjs({
include: ["node_modules/**"],
extensions: ['.ts', '.js'],
namedExports: {
"node_modules/react/react.js": [
"Children",
"Component",
"PropTypes",
"createElement"
],
"node_modules/react-dom/index.js": ["render"]
}
}),
typescript(),
postcss(),
]
export default {
input: "src/index.ts",
output: [
{
file: pkg.main,
format: "cjs",
exports: "named",
sourcemap: true
},
{
file: pkg.module,
format: "es",
exports: "named",
sourcemap: true
}
],
plugins,
external: ['react', 'react-dom', 'react-datepicker2'],
};
package.json
"main": "dist/bundle.js",
"module": "dist/bundle.es.js",
"files": [
"build"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack serve --mode=development --config webpack.dev.js --open --hot",
"build": "rollup -c",
"compile": "webpack"
},
"author": "synapps",
"license": "ISC",
"dependencies": {
"#types/jest": "^26.0.20",
"#types/react-select": "^4.0.15",
"react-select": "^4.3.0",
"react-textarea-autosize": "^8.3.2",
"react-datepicker2": "^3.3.13"
},
"devDependencies": {
"#babel/core": "^7.12.16",
"#babel/plugin-proposal-class-properties": "^7.13.0",
"#babel/preset-env": "^7.12.16",
"#babel/preset-react": "^7.12.13",
"#babel/preset-typescript": "^7.13.0",
"#types/moment-jalaali": "^0.7.4",
"#typescript-eslint/eslint-plugin": "^4.22.0",
"#typescript-eslint/parser": "^4.22.0",
"babel-loader": "^8.2.2",
"babel-polyfill": "^6.26.0",
"clean-webpack-plugin": "^3.0.0",
"css-loader": "^5.2.4",
"eslint": "^7.25.0",
"eslint-plugin-react": "^7.23.2",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.1.0",
"moment-jalaali": "^0.9.2",
"postcss": "^8.2.13",
"react": "^17.0.2",
"react-datepicker2": "^3.3.13",
"react-dom": "^17.0.2",
"react-jss": "^10.5.1",
"rollup": "^2.41.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-eslint": "^7.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-typescript": "^1.0.1",
"rollup-plugin-typescript2": "^0.30.0",
"style-loader": "^2.0.0",
"ts-lint": "^4.5.1",
"tslib": "^2.2.0",
"tslint-react": "^5.0.0",
"typescript": "^4.2.4",
"typings-for-css-modules-loader": "^1.7.0",
"url-loader": "^4.1.1",
"webpack": "^5.22.0",
"webpack-cli": "^4.5.0",
"webpack-dev-server": "^3.11.2",
"webpack-merge": "^5.7.3"
},
"peerDependencies": {
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-datepicker2": "^3.3.13",
"#types/node": "^14.14.31",
"#types/react": "^17.0.3",
"#types/react-dom": "^17.0.2",
"#types/react-select": "^4.0.15"
},
When I bundle and import it in another project I face this error:
Error: 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 renderer (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
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem
I search a lot and I know that I should externalize react to do not face a conflict of using more than one version of react. Besides I Could solve this issue with WebpackAlias, and I use customize-cra package to solve this issue.
config.overrides.js
const { override, addWebpackAlias } = require('customize-cra');
const path = require('path');
module.exports = override(
addWebpackAlias({
['react']: path.resolve('./node_modules/react')
})
);
But other issue arises and I need to know how solve this issue with rollup itself not configuring target project.
Please accept my excuse in advance for posting a lot of code but all was config files don't know how make a playground for this.

Deploy React-Redux webpack on heroku

Well, Im having a big problem, I have a front-end only react that send request to a ruby on rails api, we use redux, babel and webpack. My problem is, I cant make this react project work on Heroku.
This is a 503 response error from heroku.
Package.json:
{
"name": "real-networking-ui",
"version": "1.0.0",
"description": "Real Netoworking UI",
"main": "index.js",
"scripts": {
"start": "node -r babel-register ./node_modules/webpack-dev-server/bin/webpack-dev-server --config ./webpack.config.dev.js --progress --profile --colors",
"build": "node -r babel-register ./node_modules/webpack/bin/webpack --config ./webpack.config.prod --progress --profile --colors",
"lint": "eslint app test *.js"
},
"engines": {
"node": "6.6.0"
},
"author": "",
"license": "ISC",
"devDependencies": {
"autoprefixer": "^6.3.6",
"babel-core": "^6.10.4",
"babel-eslint": "^6.1.0",
"babel-loader": "^6.2.4",
"babel-plugin-dev-expression": "^0.2.1",
"babel-plugin-lodash": "^3.2.11",
"babel-plugin-react-transform": "^2.0.2",
"babel-plugin-transform-remove-console": "^6.8.0",
"babel-plugin-transform-remove-debugger": "^6.8.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.11.1",
"babel-preset-react-hmre": "^1.1.1",
"babel-preset-react-optimize": "^1.0.1",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.9.0",
"classnames": "^2.2.5",
"css-loader": "^0.23.1",
"eslint": "^2.13.1",
"eslint-config-airbnb": "^9.0.1",
"eslint-import-resolver-webpack": "^0.3.2",
"eslint-loader": "^1.6.1",
"eslint-plugin-import": "^1.10.0",
"eslint-plugin-jsx-a11y": "^1.5.3",
"eslint-plugin-react": "^5.2.2",
"extract-text-webpack-plugin": "^1.0.1",
"html-webpack-plugin": "^2.21.0",
"json-loader": "^0.5.4",
"postcss-css-variables": "^0.5.1",
"postcss-loader": "^0.9.1",
"postcss-mixins": "^5.0.0",
"postcss-nested": "^1.0.0",
"postcss-partial-import": "^1.3.0",
"react-transform-hmr": "^1.0.4",
"style-loader": "^0.13.1",
"svg-react": "^1.0.9",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1"
},
"dependencies": {
"axios": "^0.15.3",
"core-js": "^2.4.1",
"css-loader": "^0.23.1",
"lodash": "^4.17.2",
"moment": "^2.17.1",
"node-sass": "^3.13.0",
"react": "^15.1.0",
"react-dom": "^15.1.0",
"react-hot-loader": "^3.0.0-beta.6",
"react-maskedinput": "^3.3.1",
"react-modal": "^1.6.4",
"react-redux": "^4.4.5",
"react-router": "^3.0.0",
"react-router-redux": "^4.0.5",
"react-select": "^1.0.0-rc.2",
"react-select-box": "^3.0.1",
"redux": "^3.5.2",
"redux-thunk": "^2.1.0",
"sass-loader": "^4.0.2",
"style-loader": "^0.13.1",
"svg-react": "^1.0.9",
"validator": "^6.2.0",
"whatwg-fetch": "^2.0.1"
},
"eslintConfig": {
"extends": "react-app"
},
"babel": {
"presets": [
"react-app"
]
}
}
webpack.config.base:
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
export default {
entry: './app/app.js',
output: {
path: './app/App/dist',
filename: '/bundle.js',
},
module: {
loaders: [
{
test: /\.json$/,
loader: 'json',
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('css!sass'),
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('css!sass'),
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.svg$/,
loader: 'babel?presets[]=es2015,presets[]=react!svg-react',
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './app/App/index.html',
}),
new ExtractTextPlugin('/app/App/css/default.css', {
allChunks: true,
}),
],
};
webpack.config.dev:
import webpack from 'webpack';
import baseConfig from './webpack.config.base';
const config = {
...baseConfig,
debug: true,
devtool: 'cheap-module-eval-source-map',
plugins: [
...baseConfig.plugins,
new webpack.HotModuleReplacementPlugin(),
],
devServer: {
colors: true,
historyApiFallback: true,
inline: true,
hot: true,
},
};
export default config;
webpack.config.prod.js:
import webpack from 'webpack';
import baseConfig from './webpack.config.base';
const config = {
...baseConfig,
plugins: [
...baseConfig.plugins,
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compressor: {
screw_ie8: true,
warnings: false,
},
}),
],
};
export default config;
Procfile:
web: npm start
If you need more information about that tell me that I edit it.
Thank you for the help.
The heroku default configuration is to cache the dependencies in node_modules and set production environment to true.
Caching node_modules prevents additional modules from getting installed.
Production Environment prevents devDependencies in package.json from getting installed.
Refer to this link to solve the above problems
Also, webpack-dev-server doesn't work in Heroku, so it's better to create a small web server (Personally I like Express server) to serve the dist folder and then deploy the app.
Additionally, If you are still facing the problem, try running heroku logs --tail and paste the logs here.
My take on this is the devDependencies should be re-installed under dependencies. Under similar circumstances I had the error screen when trying to deploy on Heroku. The devDependencies are ignored and whenever your code asks for them Heroku alarms.

"The use of a keyword for an identifier is invalid" error when loading React app that uses Webpack in Windows Edge 13

I'm totally stumped on this error. I've been investigating this for days to no avail.
It is a fairly complex web app that uses React, Webpack and Babel to run. The error I get in the Edge console seems to related to Webpack, so I've added a couple of polyfills but that didn't change anything.
I haven't seen anyone else encountering this error, which I find surprising. I've updated all node packages but that didn't fix it either.
Here is the package.json, I currently have:
{
"name": "some-app",
"private": true,
"dependencies": {
"babel-core": "^5.8.22",
"babel-loader": "^5.3.2",
"babel-polyfill": "^6.5.0",
"babel-relay-plugin": "^0.3.0",
"chart.js": "^1.0.2",
"css-loader": "^0.22.0",
"es5-shim": "^4.5.7",
"graphiql": "0.3.1",
"history": "1.13.1",
"isomorphic-fetch": "^2.1.1",
"jsxstyle": "^0.0.17",
"mockdate": "1.0.3",
"moment": "^2.10.2",
"react": "^0.14.0",
"react-addons-shallow-compare": "^0.14.0",
"react-chartjs": "^0.6.0",
"react-dom": "^0.14.0",
"react-loader": "^2.0.0",
"react-relay": "^0.4.0",
"react-router": "1.0.0-rc3",
"react-router-relay": "^0.7.0",
"style-loader": "^0.12.3",
"superagent": "^1.2.0",
"underscore": "^1.8.3",
"webpack": "^1.12.13"
},
"devDependencies": {
"babel-eslint": "^3.1.30",
"babel-jest": "^5.3.0",
"classnames": "^2.2.3",
"eslint": "^0.23",
"eslint-config-airbnb": "0.0.7",
"eslint-plugin-react": "^3.2.2",
"jest-cli": "^0.5.0",
"react-addons-test-utils": "^0.14.0-beta3"
},
"scripts": {
"test": "node node_modules/.bin/jest --verbose --runInBand",
"build": "node node_modules/.bin/webpack",
"postinstall": "npm run build"
},
"jest": {
"rootDir": "",
"scriptPreprocessor": "node_modules/babel-jest",
"preprocessorIgnorePatterns": [
"<rootDir>/node_modules/"
],
"testPathDirs": [
"<rootDir>/src/"
],
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react/",
"<rootDir>/node_modules/react-dom/",
"<rootDir>/node_modules/react-addons-test-utils/",
"<rootDir>/node_modules/react-relay/",
"<rootDir>/node_modules/react-router/",
"<rootDir>/node_modules/react-sticky/",
"<rootDir>/node_modules/jsxstyle/",
"<rootDir>/node_modules/underscore/",
"<rootDir>/src/__tests__/",
"<rootDir>/src/components/delay/",
"<rootDir>/src/mutations/",
"<rootDir>/src/components/react-wrapper"
]
}
}
Can anyone see anything obvious as to why the app wouldn't run at all in Edge 13? The error I get in the console is:
Anything that gets me on the right track, I'd appreciate!
Edit
My webpack.config looks like this:
module.exports = {
entry: {
academy: "./src/app.js"
},
output: {
filename: "../website/app/assets/javascripts/academy/[name].js"
},
module: {
loaders: [
{ test: /\.js$/, loaders: ["babel-loader"], exclude: /node_modules/ },
{ test: /\.css$/, loader: "style-loader!css-loader" }
]
},
resolve: {
extensions: ["", ".js"]
},
devtool: process.env.NODE_ENV !== "production" ? "eval-source-map" : null
};

Resources