I have this really weird "bug" I guess you can call it with eslint when I try and run yarn lint
$ tsc --noEmit && eslint src/**/*.ts{,x}
For some reason it fails with
Oops! Something went wrong! :(
ESLint: 7.32.0
TypeError: Cannot read property 'name' of undefined
Occurred while linting /Users/Reynaldo/Documents/cafemat/src/hooks/useFirebase.ts:13
at ExpressionStatement (/Users/Reynaldo/Documents/cafemat/node_modules/eslint-plugin-storybook/lib/rules/prefer-csf.js:18:44)
at /Users/Reynaldo/Documents/cafemat/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/Users/Reynaldo/Documents/cafemat/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/Users/Reynaldo/Documents/cafemat/node_modules/eslint/lib/linter/node-event-generator.js:293:26)
at NodeEventGenerator.applySelectors (/Users/Reynaldo/Documents/cafemat/node_modules/eslint/lib/linter/node-event-generator.js:322:22)
at NodeEventGenerator.enterNode (/Users/Reynaldo/Documents/cafemat/node_modules/eslint/lib/linter/node-event-generator.js:336:14)
at CodePathAnalyzer.enterNode (/Users/Reynaldo/Documents/cafemat/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)
at /Users/Reynaldo/Documents/cafemat/node_modules/eslint/lib/linter/linter.js:960:32
at Array.forEach (<anonymous>)
error Command failed with exit code 2.
Also, if I have my useFirebase.ts file focused (in view) on VSCode and run yarn start I get the error:
Failed to compile
Cannot read property 'name' of undefined
Occurred while linting /Users/Reynaldo/Documents/cafemat/src/hooks/useFirebase.ts:13
This error occurred during the build time and cannot be dismissed.
Yet if I put in focus (into view) any other file on VSCode and run yarn start the project compiles and runs without problems.
Is this a weird bug or am I doing something wrong? Here are the files:
useFirebase.ts
import { useEffect, useState } from "react";
import { FirebaseApp, deleteApp, getApp, initializeApp } from "firebase/app";
import { appName, firebaseConfig } from "../config/firebaseConfig";
function useFirebase(): FirebaseApp | null {
const [firebaseApp, setFirebaseApp] = useState<FirebaseApp | null>(null);
useEffect(() => {
let app: FirebaseApp;
try {
app = getApp(appName);
}
catch (err) {
app = initializeApp(firebaseConfig, appName);
}
setFirebaseApp(app);
return () => {
deleteApp(app);
};
}, []);
return firebaseApp;
}
export default useFirebase;
package.json
{
"name": "xxxxxxx",
"version": "0.1.0",
"private": true,
"dependencies": {
"#reach/router": "1.3.4",
"firebase": "9.1.3",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-helmet-async": "1.1.2",
"react-scripts": "4.0.3",
"web-vitals": "1.0.1"
},
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject",
"format": "prettier --write 'src/**/*.ts{,x}'",
"lint": "tsc --noEmit && eslint src/**/*.ts{,x}",
"cypress:open": "cypress open",
"storybook": "start-storybook -p 6006 -s public",
"build-storybook": "build-storybook -s public",
"serve": "serve -s build"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
],
"overrides": [
{
"files": [
"**/*.stories.*"
],
"rules": {
"import/no-anonymous-default-export": "off"
}
}
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#craco/craco": "^6.2.0",
"#storybook/addon-actions": "^6.3.2",
"#storybook/addon-essentials": "^6.3.2",
"#storybook/addon-links": "^6.3.2",
"#storybook/node-logger": "^6.3.2",
"#storybook/preset-create-react-app": "^3.1.7",
"#storybook/react": "^6.3.2",
"#tailwindcss/postcss7-compat": "^2.2.4",
"#testing-library/jest-dom": "^5.14.1",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"#types/jest": "^26.0.15",
"#types/node": "^12.0.0",
"#types/reach__router": "^1.3.9",
"#types/react": "^17.0.13",
"#types/react-dom": "^17.0.0",
"#types/react-helmet": "^6.1.2",
"#typescript-eslint/eslint-plugin": "^4.28.1",
"#typescript-eslint/parser": "^4.28.1",
"autoprefixer": "^9",
"babel-loader": "8.1.0",
"cypress": "^7.6.0",
"eslint": "^7.2.0",
"eslint-config-airbnb": "18.2.1",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-chai-friendly": "^0.7.1",
"eslint-plugin-cypress": "^2.11.3",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.6",
"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",
"eslint-plugin-storybook": "^0.1.1",
"postcss": "^7",
"postcss-cli": "^8.3.1",
"prettier": "^2.3.2",
"tailwindcss": "npm:#tailwindcss/postcss7-compat",
"typescript": "^4.1.2"
}
}
.eslintrc
{
"extends": [
"airbnb-typescript",
"airbnb/hooks",
"plugin:#typescript-eslint/recommended",
"plugin:jest/recommended",
"plugin:prettier/recommended",
"plugin:cypress/recommended",
"plugin:chai-friendly/recommended"
],
"plugins": [
"react",
"#typescript-eslint",
"jest",
"cypress",
"chai-friendly",
"storybook"
],
"env": {
"browser": true,
"es6": true,
"jest": true,
"cypress/globals": true
},
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "#typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"linebreak-style": "off",
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
],
"cypress/no-assigning-return-values": "error",
"cypress/no-unnecessary-waiting": "error",
"cypress/assertion-before-screenshot": "warn",
"cypress/no-force": "warn",
"cypress/no-async-tests": "error",
"no-unused-expressions": 0,
"chai-friendly/no-unused-expressions": 2,
"storybook/prefer-csf": "error"
}
}
.eslintignore
# Temporary lint ignore because storybook example files
# generated files that go against specified ESLint rules.
src/stories
# ESLinting error taken off by ignoring config files
# https://stackoverflow.com/questions/58510287/parseroptions-project-has-been-set-for-typescript-eslint-parser/64488474#64488474
tailwind.config.js
postcss.config.js
craco.config.js
Ok so I solved the problem. For some reason the prefer-csf rule of eslint-plugin-storybook causes this error. Once I commented out "storybook/prefer-csf": "error" from the .eslintrc the yarn lint command runs without problems. If anyone has a clue as to why this solves the error it would be greatly appreciated if you could explain. Thanks! :D
Related
I am trying to create component library with React.js, I am using Rollup.js for this.
When I am building the app, I see this error in the console. It seems Rollup can not detect default exports, I tried to add a .babelrc file configuration but unfortunately it did not work.
What am I doing wrong and how can this problem be solved?
//rollup.config.js
import babel from 'rollup-plugin-babel';
import resolve from '#rollup/plugin-node-resolve';
import external from 'rollup-plugin-peer-deps-external';
import { terser } from 'rollup-plugin-terser';
import postcss from 'rollup-plugin-postcss';
import commonjs from '#rollup/plugin-commonjs';
export default [
{
input: './src/index.js',
output: [
{
file: 'dist/index.js',
format: 'cjs',
},
{
file: 'dist/index.es.js',
format: 'es',
exports: 'named',
}
],
plugins: [
postcss({
plugins: [],
minimize: true,
}),
babel({
exclude: "node_modules/**",
presets: ["#babel/preset-react"],
}),
external(),
resolve(),
terser(),
]
}
];
//package.json
{
"name": "test",
"version": "0.1.0",
"private": false,
"dependencies": {
"#babel/preset-stage-1": "^7.8.3",
"#rollup/plugin-commonjs": "^21.0.3",
"#rollup/plugin-replace": "^2.4.2",
"#testing-library/jest-dom": "^5.16.3",
"#testing-library/react": "^12.1.4",
"#testing-library/user-event": "^13.5.0",
"babel-preset-latest": "^6.24.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.0",
"react-transform-hmr": "^1.0.4",
"typescript": "^4.6.3",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "tsc",
"test": "react-scripts test",
"eject": "react-scripts eject",
"storybook": "start-storybook -p 6006 -s public",
"build-storybook": "build-storybook -s public",
"build-lib": "rollup -c"
},
"files": [
"dist"
],
"main": "dist/index.js",
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
],
"overrides": [
{
"files": [
"**/*.stories.*"
],
"rules": {
"import/no-anonymous-default-export": "off"
}
}
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#babel/plugin-external-helpers": "^7.16.7",
"#babel/preset-react": "^7.16.7",
"#rollup/plugin-node-resolve": "^11.2.1",
"#storybook/addon-actions": "^6.4.19",
"#storybook/addon-essentials": "^6.4.19",
"#storybook/addon-interactions": "^6.4.19",
"#storybook/addon-links": "^6.4.19",
"#storybook/builder-webpack5": "^6.4.19",
"#storybook/manager-webpack5": "^6.4.19",
"#storybook/node-logger": "^6.4.19",
"#storybook/preset-create-react-app": "^4.1.0",
"#storybook/react": "^6.4.19",
"#storybook/testing-library": "^0.0.9",
"rollup": "^2.70.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.2",
"semantic-release": "^19.0.2",
"webpack": "^5.70.0"
}
}
The error is telling you what you need to know. To explain what that means, there is no export default ... in react-dom (you can verify this by looking at the source code).
There are several ways to fix this:
Play around with some of the #rollup/plugin-commonjs settings. Sorry I can't tell you which one will work, maybe start with defaultIsModuleExports.
Import the method that you need. With react-dom, you're likely only using render, so import it like this: import { render } from 'react-dom'
Import everything and alias as ReactDOM: import * as ReactDOM from 'react-dom'
When I try to do this:
// index.js
import * as classes from './index.module.css'
I get this:
Error: Bundles must have unique names
// .parcelrc
{
"extends": "#parcel/config-webextension"
}
// babel.config.js
module.exports = {
plugins: [
[
"#babel/plugin-proposal-decorators",
{
legacy: true,
},
],
[
"#babel/plugin-proposal-class-properties",
{
loose: true,
},
],
],
presets: [
[
"#babel/preset-env",
{
targets: {
node: "current",
},
loose: true,
},
],
"#babel/preset-react",
],
}
// package.json
{
"private": true,
"scripts": {
"build": "parcel build source/manifest.json --no-content-hash --no-source-maps --dist-dir distribution --no-cache --detailed-report 0",
"lint": "run-p lint:*",
"lint-fix": "run-p 'lint:* -- --fix'",
"lint:css": "stylelint source/**/*.css",
"lint:js": "xo",
"eslint": "eslint source/**/*.js source/**/*.jsx",
"test": "run-p lint:* build",
"watch": "parcel watch source/manifest.json --dist-dir distribution --no-cache --no-hmr"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"source/**/*.{js,jsx}": [
"eslint",
"prettier --write"
],
"source/**/*.css": [
"prettier --write"
]
},
"browserslist": [
"last 1 Chrome version",
"last 1 Firefox version"
],
"xo": {
"envs": [
"browser"
],
"rules": {
"no-unused-vars": [
"error",
{
"varsIgnorePattern": "browser"
}
]
}
},
"stylelint": {
"extends": "stylelint-config-xo"
},
"dependencies": {
"#reduxjs/toolkit": "^1.8.0",
"bootstrap": "^5.1.3",
"react": "^17.0.2",
"react-bootstrap": "^2.2.1",
"react-bootstrap-typeahead": "^6.0.0-alpha.9",
"react-dom": "^17.0.2",
"react-redux": "^7.2.6",
"react-toastify": "^8.2.0",
"redux-saga": "^1.1.3",
"webext-options-sync": "^3.0.1",
"webextension-polyfill": "^0.8.0"
},
"devDependencies": {
"#babel/core": "^7.17.7",
"#babel/eslint-parser": "^7.17.0",
"#babel/plugin-proposal-class-properties": "^7.16.7",
"#babel/plugin-proposal-decorators": "^7.17.2",
"#babel/preset-env": "^7.16.11",
"#babel/preset-react": "^7.16.7",
"#parcel/config-webextension": "^2.3.2",
"#parcel/transformer-image": "^2.3.2",
"axios": "^0.26.1",
"eslint": "^8.11.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-react": "^7.29.3",
"husky": "4",
"lint-staged": "^12.3.7",
"npm-run-all": "^4.1.5",
"parcel": "^2.3.2",
"postcss": "^8.0.0",
"postcss-modules": "^4.3.0",
"prettier": "^2.5.1",
"process": "^0.11.10",
"rollup-plugin-import-css": "^3.0.3",
"stylelint": "^14.5.3",
"stylelint-config-xo": "^0.20.1",
"xo": "^0.48.0"
},
"webExt": {
"sourceDir": "distribution"
}
}
Error stacktrace
Error: Bundles must have unique names
AssertionError [ERR_ASSERTION]: Bundles must have unique names
at BundlerRunner.nameBundles
(/Users/Goldy/apps/web-extension/node_modules/#parcel/core/lib/requests/BundleGraphRequest.js:343:23)
at async BundlerRunner.bundle
(/Users/Goldy/apps/web-extension/node_modules/#parcel/core/lib/requests/BundleGraphRequest.js:286:5)
at async RequestTracker.runRequest
(/Users/Goldy/apps/web-extension/node_modules/#parcel/core/lib/RequestTracker.js:725:20)
at async Object.run
(/Users/Goldy/apps/web-extension/node_modules/#parcel/core/lib/requests/ParcelBuildRequest.js:62:7)
at async RequestTracker.runRequest
(/Users/Goldy/apps/web-extension/node_modules/#parcel/core/lib/RequestTracker.js:725:20)
at async Parcel._build
(/Users/Goldy/apps/web-extension/node_modules/#parcel/core/lib/Parcel.js:397:11)
at async Parcel._startNextBuild
(/Users/Goldy/apps/web-extension/node_modules/#parcel/core/lib/Parcel.js:298:24)
at async $b0fd219fea43bcac$export$2e2bcd8739ae039._runFn
(/Users/Goldy/apps/web-extension/node_modules/#parcel/utils/lib/index.js:32645:13)
at async $b0fd219fea43bcac$export$2e2bcd8739ae039._next
(/Users/Goldy/apps/web-extension/node_modules/#parcel/utils/lib/index.js:32638:9)
What am I missing here?
I also tried to add the following file with no effect:
// .postcssrc.js
module.exports = {
modules: true,
plugins: {
"postcss-modules": {
generateScopedName: "[folder]__[local]___[hash:base64:6]",
},
},
}
I am trying to build the react.js project with npm run build, I am getting following error, I have tried many solution but nothing is working for me.
**Failed to compile.**
Rules with suggestions must set the `meta.hasSuggestions` property to `true`.
`meta.docs.suggestion` is ignored by ESLint.
Occurred while linting
/Users/e0658897/Desktop//Electrical%20-
%20Web%20Portal/src/reportWebVitals.ts:6
Rule: "#typescript-eslint/no-floating-promises"
This breaks all other linting. I've tried adding the following to my .eslintrc.js:
meta: {
hasSuggestions: true
},
which gives me the following error:
UnhandledPromiseRejectionWarning: Error: ESLint configuration in .eslintrc.js is invalid:
- Unexpected top-level property "meta".
Package.json
{
"name": "proxusweb",
"version": "0.1.0",
"private": true,
"dependencies": {
"#brightlayer-ui/icons-mui": "^2.8.1",
"#brightlayer-ui/react-auth-workflow": "^2.4.0",
"#brightlayer-ui/react-components": "^5.3.3",
"#brightlayer-ui/react-themes": "^6.1.0",
"#material-ui/core": "^4.11.4",
"#material-ui/icons": "^4.11.2",
"#material-ui/lab": "^4.0.0-alpha.60",
"axios": "^0.26.0",
"date-fns": "^2.28.0",
"i18next": "^19.9.2",
"jspdf": "^2.5.1",
"jspdf-autotable": "^3.5.23",
"react": "^17.0.2",
"react-app-polyfill": "^3.0.0",
"react-dom": "^17.0.2",
"react-i18next": "^11.15.3",
"react-router": "^5.2.1",
"react-router-dom": "^5.3.0",
"react-scripts": "5.0.0",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint": "eslint \"src/**/**.{ts,tsx}\"",
"lint:fix": "eslint \"src/**/**.{ts,tsx}\" --fix",
"prettier": "prettier \"src/**/**.{ts,tsx,js,jsx,json,css,scss,html}\" --write",
"prettier:check": "prettier \"src/**/**.{ts,tsx,js,jsx,json,css,scss,html}\" --check"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#brightlayer-ui/eslint-config": "^2.0.5",
"#brightlayer-ui/prettier-config": "^1.0.3",
"#testing-library/jest-dom": "^5.16.1",
"#testing-library/react": "^11.2.7",
"#testing-library/user-event": "^13.5.0",
"#types/enzyme-adapter-react-16": "^1.0.6",
"#types/jest": "^26.0.24",
"#types/node": "^12.20.42",
"#types/react": "^17.0.38",
"#types/react-dom": "^17.0.11",
"#types/react-router-dom": "^5.3.3",
"#typescript-eslint/eslint-plugin": "^4.33.0",
"#typescript-eslint/parser": "^4.33.0",
"#wojtekmaj/enzyme-adapter-react-17": "^0.6.6",
"enzyme": "^3.11.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.2.1-rc.1-next-f0dd459e0-20220301",
"prettier": "^2.5.1",
"typescript": "^4.5.5"
},
"prettier": "#brightlayer-ui/prettier-config"
}
.eslinrc.js
module.exports = {
root: true,
parser: '#typescript-eslint/parser',
extends: ['#brightlayer-ui/eslint-config/tsx'],
// meta:{
// hasSuggestions: true
// },
parserOptions: {
project: "./tsconfig.json",
},
env: {
browser: true
},
rules: {
// "#typescript-eslint/explicit-function-return-type": "off",
"#typescript-eslint/explicit-function-return-type": [
"error",
{
"allowExpressions": true
}
],
"no-unused-vars": "off",
"no-undef": "off",
"arrow-body-style": "off",
"#typescript-eslint/no-unused-vars": "off",
'no-console': 'off',
"no-alert": "off",
"react-hooks/exhaustive-deps": "off",
"react-hooks/rule-of-hooks": "off",
},
};
All I found about this case https://eslint.org/docs/user-guide/migrating-to-8.0.0#-rules-require-metahassuggestions-to-provide-suggestions
But I didn't successfully remove the problem, only solution for now is to turn off the rule that's causing it
I was getting the same error when I was running my React.js application, you can see it in the image below:
Running the following command solved the problem: npm install -D eslint-plugin-react-hooks#next
I figured it out reading this GitHub discussion: Bug: Rules with suggestions must set the meta.hasSuggestions property to true
I'm trying to deploy an app to Heroku, it's working perfectly in my local. But in Heroku show me: =>
Failed to compile
Failed to load config "airbnb" to extend from.
Referenced from: /app/.eslintrc.json
This error occurred during the build time and cannot be dismissed.
I try to fix it by installing airbn in the Heroku console. But didn't work. I appreciate if you could help me.
Here is my package.json file =>
{
"name": "calculator",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.12.0",
"#testing-library/react": "^11.2.6",
"#testing-library/user-event": "^12.8.3",
"big.js": "^6.1.1",
"prop-types": "^15.7.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-vitals": "^1.1.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#babel/core": "^7.14.0",
"#babel/eslint-parser": "^7.13.14",
"#babel/plugin-syntax-jsx": "^7.12.13",
"#babel/preset-react": "^7.13.13",
"eslint": "^7.25.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.23.2",
"eslint-plugin-react-hooks": "^4.2.0",
"stylelint": "^13.13.1",
"stylelint-config-standard": "^21.0.0",
"stylelint-csstree-validator": "^1.9.0",
"stylelint-scss": "^3.19.0"
}
}
and here my eslint configuration =>
{
"env": {
"browser": true,
"es6": true,
"jest": true
},
"parser": "#babel/eslint-parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"extends": ["airbnb", "plugin:react/recommended"],
"plugins": ["react"],
"rules": {
"react/jsx-filename-extension": ["warn", { "extensions": [".js", ".jsx"] }],
"react/react-in-jsx-scope": "off",
"import/no-unresolved": "off",
"no-shadow": "off"
},
"ignorePatterns": [
"dist/",
"build/"
]
}
I had to follow these steps and that fixed it.
1| heroku create $APP_NAME --buildpack mars/create-react-app
2| git push heroku HEAD:master
Replace $APP_NAME with the name of your unique app.
here is the documentation link:
github.com/mars/create-react-app-buildpack
I was experiencing the same issues and finally what worked was to move "eslint-config-airbnb" from "devDependencies" to "dependencies" as indicated by eamanola.
Also, my context was a bit different, as I was running a create-react-app and express app.
Is it possible to use export * from './X' with absolute import paths and eslint in react/typescript? I wanted to have single index.ts file in components folder that would export everything else but eslint gives me weird error when i'm trying to do this.
My current structure looks like this:
src/components/Example1/Example1.tsx
import React from 'react';
export type Props = {};
export const Example1 = (props: Props) => <div></div>
src/components/Example1/index.ts
export * from './Example1';
src/components/index.ts
export * from './Example1';
Both index files gives me error:
0:0 error Parsing error: Cannot read property 'name' of undefined
Also when i try to import anything from the components/index file using an absolute path import { Example1 } from 'components'; i have an error:
1:43 error Parse errors in imported module 'components': Cannot read property 'name' of undefined (undefined:undefined) import/namespace
1:43 error Parse errors in imported module 'components': Cannot read property 'name' of undefined (undefined:undefined) import/named
This is my .eslintrc.json file
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"root": true,
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:#typescript-eslint/eslint-recommended",
"plugin:import/warnings",
"plugin:import/errors",
"plugin:import/typescript",
"prettier/#typescript-eslint",
"prettier",
"prettier/react"
],
"plugins": [
"react",
"react-hooks",
"jsx-a11y",
"#typescript-eslint",
"prettier"
],
"parser": "#typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"settings": {
"react": {
"version": "detect"
},
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"],
"moduleDirectory": ["node_modules", "src/"]
}
}
},
"rules": {
"prettier/prettier": "error",
"import/newline-after-import": "error",
"no-unused-vars": "off",
"#typescript-eslint/no-unused-vars": [
"warn",
{ "args": "after-used", "argsIgnorePattern": "^_" }
]
}
}
This is my tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react",
"baseUrl": "./src"
},
"include": ["src"]
}
My current package.json:
{
"name": "frontend",
"version": "0.0.0",
"license": "MIT",
"private": true,
"dependencies": {
"#apollo/react-hooks": "^3.1.3",
"#material-ui/core": "^4.9.5",
"#material-ui/icons": "^4.9.1",
"#material-ui/styles": "^4.9.0",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"#types/jest": "^24.0.0",
"#types/material-ui": "^0.21.7",
"#types/node": "^12.0.0",
"#types/react": "^16.9.0",
"#types/react-dom": "^16.9.0",
"#types/react-router-dom": "^5.1.3",
"#types/styled-components": "^5.0.1",
"#types/yup": "^0.26.32",
"apollo-boost": "^0.4.7",
"env-cmd": "^10.1.0",
"formik": "^2.1.4",
"graphql": "^14.6.0",
"i18next": "^19.3.3",
"i18next-browser-languagedetector": "^4.0.2",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-i18next": "^11.3.3",
"react-router-dom": "^5.1.2",
"react-scripts": "3.4.0",
"styled-components": "^5.0.1",
"typescript": "~3.7.2",
"yup": "^0.28.3"
},
"devDependencies": {
"#typescript-eslint/eslint-plugin": "^2.23.0",
"#typescript-eslint/parser": "^2.23.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.2",
"prettier": "^1.19.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build:staging": "env-cmd -f .env.staging yarn build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint": "tsc --noEmit && eslint . --ext .js,.tsx,.ts --max-warnings=0",
"lint:fix": "eslint . --ext .js,.tsx,.ts --fix",
"watch": "react-scripts start",
"deploy": "yarn build && firebase deploy",
"deploy:staging": "yarn build:staging && firebase use staging && firebase deploy"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
I'm also using lerna with yarn workspaces to easily handle MERN app.
Deleting eslint package / configs, node_modules did not help me, i still have Cannot read property 'name' of undefined error. It is super weird because in clean CRA everything works. I spent last 4 hours trying to solve this problem and finally used a workaround with importing types to root index file and reexporing them as new type but it's definately a painful solution. I need to keep isolatedModules. Maybe someone had similar problem?
The problem was #typescript-eslint package, check out the issue for more info:
https://github.com/typescript-eslint/typescript-eslint/issues/1746
Fast fix for this is to downgrade packages to version 2.22.0:
#typescript-eslint/eslint-plugin
#typescript-eslint/parser
#Edit This helped with lint error but my CRA build is still crashing, I guess i will have to wait for package fix