Explore all Jest open source software, libraries, packages, source code, cloud functions and APIs.

Popular New Releases in Jest

jest

v28.0.0-alpha.11

react-testing-library

v13.1.1

tsdx

v0.14.1

ts-jest

v27.1.4

react-hooks-testing-library

v8.0.0

Popular Libraries in Jest

nodebestpractices

by goldbergyoni doticonjavascriptdoticon

star image 76719 doticonCC-BY-SA-4.0

:white_check_mark: The Node.js best practices list (March 2022)

jest

by facebook doticontypescriptdoticon

star image 38648 doticonMIT

Delightful JavaScript Testing.

react-starter-kit

by kriasoft doticontypescriptdoticon

star image 21150 doticonMIT

React Starter Kit β€” front-end starter kit using React, Relay, GraphQL, and JAM stack architecture

javascript-testing-best-practices

by goldbergyoni doticonjavascriptdoticon

star image 16734 doticonMIT

πŸ“—πŸŒ 🚒 Comprehensive and exhaustive JavaScript & Node.js testing best practices (April 2022)

react-testing-library

by testing-library doticonjavascriptdoticon

star image 16240 doticonMIT

🐐 Simple and complete React DOM testing utilities that encourage good testing practices.

TypeScript-React-Starter

by microsoft doticontypescriptdoticon

star image 10678 doticonMIT

A starter template for TypeScript and React with a detailed README describing how to use the two together.

sinon

by sinonjs doticonjavascriptdoticon

star image 8951 doticonNOASSERTION

Test spies, stubs and mocks for JavaScript.

tsdx

by formium doticonjavascriptdoticon

star image 8143 doticonMIT

Zero-config CLI for TypeScript package development

majestic

by Raathigesh doticontypescriptdoticon

star image 7184 doticonMIT

⚑ Zero config GUI for Jest

Trending New libraries in Jest

nodejs-integration-tests-best-practices

by testjavascript doticonjavascriptdoticon

star image 1892 doticon

βœ… Master the art of the most powerful testing technique for Node.js: Component tests. Including super-comprehensive best practices list and an example app (November 2021)

superplate

by pankod doticontypescriptdoticon

star image 1627 doticon

A well-structured production-ready frontend boilerplate with Typescript, Jest, testing-library, styled-component, Sass, Css, .env, Fetch, Axios, Reverse Proxy, Bundle Analyzer and 30+ plugin. For now, only creates projects for React and Next.js. https://pankod.github.io/superplate/

nodejs-backend-architecture-typescript

by afteracademy doticontypescriptdoticon

star image 1473 doticonApache-2.0

Node.js Backend Architecture Typescript - Learn to build a backend server for Blogging platform like Medium, FreeCodeCamp, MindOrks, AfterAcademy - Learn to write unit and integration tests - Learn to use Docker image - Open-Source Project By AfterAcademy

electron-typescript-react

by diego3g doticonjavascriptdoticon

star image 1192 doticon

:electron: An Electron boilerplate including TypeScript, React, Jest and ESLint.

next-right-now

by UnlyEd doticonhtmldoticon

star image 807 doticonMIT

Flexible production-grade boilerplate with Next.js 11, Vercel and TypeScript. Includes multiple opt-in presets using Storybook, Airtable, GraphQL, Analytics, CSS-in-JS, Monitoring, End-to-end testing, Internationalization, CI/CD and SaaS B2B multi single-tenancy (monorepo) support

snapchat-clone

by TowhidKashem doticontypescriptdoticon

star image 793 doticonMIT

πŸ‘» A SnapChat clone built with React, Redux and Typescript. Styled with SASS. Tested with Cypress, Jest and Enzyme. Linted with Eslint and formatted with Prettier!

playwright-test

by microsoft doticontypescriptdoticon

star image 780 doticonNOASSERTION

Build a cross-browser end-to-end test suite with Playwright.

esbuild-node-tsc

by a7ul doticonjavascriptdoticon

star image 608 doticonMIT

Build your Typescript Node.js projects using blazing fast esbuild

testing-react

by storybookjs doticontypescriptdoticon

star image 539 doticonMIT

Testing utilities that allow you to reuse your Storybook stories in your React unit tests!

Top Authors in Jest

1

testing-library

13 Libraries

star icon29972

2

kentcdodds

13 Libraries

star icon3273

3

maksimyaromin

11 Libraries

star icon24

4

nrwl

11 Libraries

star icon556

5

softspiders

11 Libraries

star icon23

6

bahmutov

11 Libraries

star icon382

7

monsterlessons

11 Libraries

star icon44

8

jest-community

11 Libraries

star icon5101

9

e2e-boilerplate

10 Libraries

star icon75

10

microsoft

10 Libraries

star icon14424

1

13 Libraries

star icon29972

2

13 Libraries

star icon3273

3

11 Libraries

star icon24

4

11 Libraries

star icon556

5

11 Libraries

star icon23

6

11 Libraries

star icon382

7

11 Libraries

star icon44

8

11 Libraries

star icon5101

9

10 Libraries

star icon75

10

10 Libraries

star icon14424

Trending Kits in Jest

No Trending Kits are available at this moment for Jest

Trending Discussions on Jest

Error while loading rule 'prettier/prettier': context.getPhysicalFilename is not a function

Invalid options object. Dev Server has been initialized using an options object that does not match the API schema

The unauthenticated git protocol on port 9418 is no longer supported

Consider using the "jsdom" test environment

Making a JSX syntax for a MockComponent and have it typed with typescript

ESlint - Error: Must use import to load ES Module

Switch' is not exported from 'react-router-dom'

"Cannot read properties of undefined (reading 'pathname')" when testing pages in the v6 React Router

eslint / typescript: Unable to resolve path to module

Vue 3: Module '"../../node_modules/vue/dist/vue"' has no exported member

QUESTION

Error while loading rule 'prettier/prettier': context.getPhysicalFilename is not a function

Asked 2022-Apr-04 at 13:24

I am learning react js. I am a very beginner at this topic. But when I am doing setup to create a react environment I got an error. I have tried to solve the problem by Charles Stover blog in medium. But I got an error Command "up" not found.

Here's my index.js file:

1import React from 'react';
2import ReactDOM from 'react-dom';
3import App from './App';
4import reportWebVitals from './reportWebVitals';
5ReactDOM.render(
6   <React.StrictMode>
7      <App />
8   </React.StrictMode>,
9document.getElementById('root')
10);
11reportWebVitals();
12

My package.json file:

1import React from 'react';
2import ReactDOM from 'react-dom';
3import App from './App';
4import reportWebVitals from './reportWebVitals';
5ReactDOM.render(
6   <React.StrictMode>
7      <App />
8   </React.StrictMode>,
9document.getElementById('root')
10);
11reportWebVitals();
12{
13  "name": "myreact",
14  "version": "0.1.0",
15  "private": true,
16  "dependencies": {
17    "@testing-library/jest-dom": "^5.11.4",
18    "@testing-library/react": "^11.1.0",
19    "@testing-library/user-event": "^12.1.10",
20    "react": "^17.0.2",
21    "react-dom": "^17.0.2",
22    "react-scripts": "4.0.3",
23    "web-vitals": "^1.0.1"
24  },
25  "scripts": {
26    "start": "react-scripts start",
27    "build": "react-scripts build",
28    "test": "react-scripts test",
29    "eject": "react-scripts eject",
30    "lint": "yarn add -D prettier && yarn add -D babel-eslint && npx install-peerdeps --dev eslint-config-airbnb && yarn add -D eslint-config-prettier eslint-plugin-prettier"
31  },
32  "eslintConfig": {
33    "extends": [
34      "react-app",
35      "react-app/jest"
36    ]
37  },
38  "browserslist": {
39    "production": [
40      ">0.2%",
41      "not dead",
42      "not op_mini all"
43    ],
44    "development": [
45      "last 1 chrome version",
46      "last 1 firefox version",
47      "last 1 safari version"
48    ]
49  },
50  "devDependencies": {
51    "babel-eslint": "^10.1.0",
52    "eslint": "7.2.0",
53    "eslint-config-airbnb": "18.2.1",
54    "eslint-config-prettier": "^8.3.0",
55    "eslint-plugin-import": "2.22.1",
56    "eslint-plugin-jsx-a11y": "6.4.1",
57    "eslint-plugin-prettier": "^4.0.0",
58    "eslint-plugin-react": "7.21.5",
59    "eslint-plugin-react-hooks": "1.7.0",
60    "prettier": "^2.3.2"
61  }
62}
63

When I am running yarn start in terminal, I am getting an error.

1import React from 'react';
2import ReactDOM from 'react-dom';
3import App from './App';
4import reportWebVitals from './reportWebVitals';
5ReactDOM.render(
6   <React.StrictMode>
7      <App />
8   </React.StrictMode>,
9document.getElementById('root')
10);
11reportWebVitals();
12{
13  "name": "myreact",
14  "version": "0.1.0",
15  "private": true,
16  "dependencies": {
17    "@testing-library/jest-dom": "^5.11.4",
18    "@testing-library/react": "^11.1.0",
19    "@testing-library/user-event": "^12.1.10",
20    "react": "^17.0.2",
21    "react-dom": "^17.0.2",
22    "react-scripts": "4.0.3",
23    "web-vitals": "^1.0.1"
24  },
25  "scripts": {
26    "start": "react-scripts start",
27    "build": "react-scripts build",
28    "test": "react-scripts test",
29    "eject": "react-scripts eject",
30    "lint": "yarn add -D prettier && yarn add -D babel-eslint && npx install-peerdeps --dev eslint-config-airbnb && yarn add -D eslint-config-prettier eslint-plugin-prettier"
31  },
32  "eslintConfig": {
33    "extends": [
34      "react-app",
35      "react-app/jest"
36    ]
37  },
38  "browserslist": {
39    "production": [
40      ">0.2%",
41      "not dead",
42      "not op_mini all"
43    ],
44    "development": [
45      "last 1 chrome version",
46      "last 1 firefox version",
47      "last 1 safari version"
48    ]
49  },
50  "devDependencies": {
51    "babel-eslint": "^10.1.0",
52    "eslint": "7.2.0",
53    "eslint-config-airbnb": "18.2.1",
54    "eslint-config-prettier": "^8.3.0",
55    "eslint-plugin-import": "2.22.1",
56    "eslint-plugin-jsx-a11y": "6.4.1",
57    "eslint-plugin-prettier": "^4.0.0",
58    "eslint-plugin-react": "7.21.5",
59    "eslint-plugin-react-hooks": "1.7.0",
60    "prettier": "^2.3.2"
61  }
62}
63Error while loading rule 'prettier/prettier': context.getPhysicalFilename is not a function
64Occurred while linting F:\react-projects\myreact\src\index.js
65

Now what should I do?

ANSWER

Answered 2021-Sep-06 at 09:40

I got two different solution.

  1. remove
1import React from 'react';
2import ReactDOM from 'react-dom';
3import App from './App';
4import reportWebVitals from './reportWebVitals';
5ReactDOM.render(
6   <React.StrictMode>
7      <App />
8   </React.StrictMode>,
9document.getElementById('root')
10);
11reportWebVitals();
12{
13  "name": "myreact",
14  "version": "0.1.0",
15  "private": true,
16  "dependencies": {
17    "@testing-library/jest-dom": "^5.11.4",
18    "@testing-library/react": "^11.1.0",
19    "@testing-library/user-event": "^12.1.10",
20    "react": "^17.0.2",
21    "react-dom": "^17.0.2",
22    "react-scripts": "4.0.3",
23    "web-vitals": "^1.0.1"
24  },
25  "scripts": {
26    "start": "react-scripts start",
27    "build": "react-scripts build",
28    "test": "react-scripts test",
29    "eject": "react-scripts eject",
30    "lint": "yarn add -D prettier && yarn add -D babel-eslint && npx install-peerdeps --dev eslint-config-airbnb && yarn add -D eslint-config-prettier eslint-plugin-prettier"
31  },
32  "eslintConfig": {
33    "extends": [
34      "react-app",
35      "react-app/jest"
36    ]
37  },
38  "browserslist": {
39    "production": [
40      ">0.2%",
41      "not dead",
42      "not op_mini all"
43    ],
44    "development": [
45      "last 1 chrome version",
46      "last 1 firefox version",
47      "last 1 safari version"
48    ]
49  },
50  "devDependencies": {
51    "babel-eslint": "^10.1.0",
52    "eslint": "7.2.0",
53    "eslint-config-airbnb": "18.2.1",
54    "eslint-config-prettier": "^8.3.0",
55    "eslint-plugin-import": "2.22.1",
56    "eslint-plugin-jsx-a11y": "6.4.1",
57    "eslint-plugin-prettier": "^4.0.0",
58    "eslint-plugin-react": "7.21.5",
59    "eslint-plugin-react-hooks": "1.7.0",
60    "prettier": "^2.3.2"
61  }
62}
63Error while loading rule 'prettier/prettier': context.getPhysicalFilename is not a function
64Occurred while linting F:\react-projects\myreact\src\index.js
65"prettier/prettier": [
66            "error",
67            {
68                "trailingComma": "es5",
69                "singleQuote": true,
70                "printWidth": 100,
71                "tabWidth": 4,
72                "semi": true,
73                "endOfLine": "auto"
74            }
75        ]

from .eslintrc folder and change react script version from 4.0.3 to 4.0.1 and run npm install.

  1. Use yarn upgrade -R eslint and change react script version from 4.0.3 to 4.0.1 and run npm install.

Source https://stackoverflow.com/questions/69069719

QUESTION

Invalid options object. Dev Server has been initialized using an options object that does not match the API schema

Asked 2022-Mar-28 at 21:08

I have been stock on this error on my project when I add "proxy": "http://localhost:6000" in my package.json.

This is the error response after yarn start.

Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.

  • options.allowedHosts[0] should be a non-empty string. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

But everything is fine when I remove the "proxy": "http://localhost:6000".

This is on my package.json:

1{
2  "name": "client",
3  "version": "0.1.0",
4  "private": true, 
5  "dependencies": {
6    "@material-ui/core": "^4.12.3",
7    "@testing-library/jest-dom": "^5.16.1",
8    "@testing-library/react": "^12.1.2",
9    "@testing-library/user-event": "^13.5.0",
10    "axios": "^0.24.0",
11    "moment": "^2.29.1",
12    "react": "^17.0.2",
13    "react-dom": "^17.0.2",
14    "react-file-base64": "^1.0.3",
15    "react-redux": "^7.2.6",
16    "react-scripts": "5.0.0",
17    "redux": "^4.1.2",
18    "redux-thunk": "^2.4.1",
19    "web-vitals": "^2.1.2"
20  },
21  "scripts": {
22    "start": "react-scripts start",
23    "build": "react-scripts build",
24    "test": "react-scripts test",
25    "eject": "react-scripts eject"
26  },
27  "eslintConfig": {
28    "extends": [
29      "react-app",
30      "react-app/jest"
31    ]
32  },
33  "browserslist": {
34    "production": [
35      ">0.2%",
36      "not dead",
37      "not op_mini all"
38    ],
39    "development": [
40      "last 1 chrome version",
41      "last 1 firefox version",
42      "last 1 safari version"
43    ]
44  },
45  "proxy": "http://localhost:6000"
46}
47

ANSWER

Answered 2021-Dec-19 at 16:06

Here is a workaround. Delete "proxy": "http://localhost:6000". Install package http-proxy-middleware with command npm install http-proxy-middleware --save. Create a file setupProxy.js inside your src folder. Add these lines inside:

1{
2  "name": "client",
3  "version": "0.1.0",
4  "private": true, 
5  "dependencies": {
6    "@material-ui/core": "^4.12.3",
7    "@testing-library/jest-dom": "^5.16.1",
8    "@testing-library/react": "^12.1.2",
9    "@testing-library/user-event": "^13.5.0",
10    "axios": "^0.24.0",
11    "moment": "^2.29.1",
12    "react": "^17.0.2",
13    "react-dom": "^17.0.2",
14    "react-file-base64": "^1.0.3",
15    "react-redux": "^7.2.6",
16    "react-scripts": "5.0.0",
17    "redux": "^4.1.2",
18    "redux-thunk": "^2.4.1",
19    "web-vitals": "^2.1.2"
20  },
21  "scripts": {
22    "start": "react-scripts start",
23    "build": "react-scripts build",
24    "test": "react-scripts test",
25    "eject": "react-scripts eject"
26  },
27  "eslintConfig": {
28    "extends": [
29      "react-app",
30      "react-app/jest"
31    ]
32  },
33  "browserslist": {
34    "production": [
35      ">0.2%",
36      "not dead",
37      "not op_mini all"
38    ],
39    "development": [
40      "last 1 chrome version",
41      "last 1 firefox version",
42      "last 1 safari version"
43    ]
44  },
45  "proxy": "http://localhost:6000"
46}
47const { createProxyMiddleware } = require('http-proxy-middleware');
48
49module.exports = function(app) {
50  app.use(
51    '/api',
52    createProxyMiddleware({
53      target: 'http://localhost:6000',
54      changeOrigin: true,
55    })
56  );
57};
58

Now, run your app. It should work.

Source https://stackoverflow.com/questions/70374005

QUESTION

The unauthenticated git protocol on port 9418 is no longer supported

Asked 2022-Mar-27 at 13:23

I have been using github actions for quite sometime but today my deployments started failing. Below is the error from github action logs

1Command: git
2Arguments: ls-remote --tags --heads git://github.com/adobe-webplatform/eve.git
3Directory: /home/runner/work/stackstream-fe/stackstream-fe
4Output:
5fatal: remote error: 
6  The unauthenticated git protocol on port 9418 is no longer supported.
7

Upon investigation, it appears that below section in my yml file is causing the issue.

1Command: git
2Arguments: ls-remote --tags --heads git://github.com/adobe-webplatform/eve.git
3Directory: /home/runner/work/stackstream-fe/stackstream-fe
4Output:
5fatal: remote error: 
6  The unauthenticated git protocol on port 9418 is no longer supported.
7    - name: Installing modules
8      run: yarn install
9

I have looked into this change log but can't seem to comprehend the issue.

Additional Details: Server: EC2 Instance Github actions steps:

1Command: git
2Arguments: ls-remote --tags --heads git://github.com/adobe-webplatform/eve.git
3Directory: /home/runner/work/stackstream-fe/stackstream-fe
4Output:
5fatal: remote error: 
6  The unauthenticated git protocol on port 9418 is no longer supported.
7    - name: Installing modules
8      run: yarn install
9  steps:
10  - name: Checkout
11    uses: actions/checkout@v2
12
13  - id: vars
14    run: |
15      if [ '${{ github.ref }}' == 'refs/heads/master' ]; then echo "::set-output name=environment::prod_stackstream" ; echo "::set-output name=api-url::api" ; elif [ '${{ github.ref }}' == 'refs/heads/staging' ]; then echo "::set-output name=environment::staging_stackstream"  ; echo "::set-output name=api-url::stagingapi" ; else echo "::set-output name=environment::dev_stackstream" ; echo "::set-output name=api-url::devapi" ; fi
16
17  - uses: pCYSl5EDgo/cat@master
18    id: slack
19    with:
20      path: .github/workflows/slack.txt
21
22  - name: Slack Start Notification
23    uses: 8398a7/action-slack@v3
24    env:
25      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
26      ENVIRONMENT: '`${{ steps.vars.outputs.environment }}`'
27      COLOR: good
28      STATUS: '`Started`'
29    with:
30      status: custom
31      fields: workflow,job,commit,repo,ref,author,took
32      custom_payload: |
33        ${{ steps.slack.outputs.text }}
34
35  - name: Installing modules
36    env:
37      REACT_APP_API_URL: 'https://${{ steps.vars.outputs.api-url }}mergestack.com/api/v1'
38    run: yarn install
39
40  - name: Create Frontend Build
41    env:
42      REACT_APP_API_URL: 'https://${{ steps.vars.outputs.api-url }}mergestack.com/api/v1'
43    run: yarn build
44
45  - name: Deploy to Frontend Server DEV
46    if: ${{ contains(github.ref, 'dev') }}
47    uses: easingthemes/ssh-deploy@v2.1.5
48    env:
49      SSH_PRIVATE_KEY: ${{ secrets.DEV_KEY }}
50      ARGS: '-rltgoDzvO --delete'
51      SOURCE: 'deploy/'
52      REMOTE_HOST: ${{ secrets.DEV_HOST }}
53      REMOTE_USER: plyfolio-dev
54      TARGET: '/home/plyfolio-dev/${{ steps.vars.outputs.environment }}/fe/deploy'
55

package.json file

1Command: git
2Arguments: ls-remote --tags --heads git://github.com/adobe-webplatform/eve.git
3Directory: /home/runner/work/stackstream-fe/stackstream-fe
4Output:
5fatal: remote error: 
6  The unauthenticated git protocol on port 9418 is no longer supported.
7    - name: Installing modules
8      run: yarn install
9  steps:
10  - name: Checkout
11    uses: actions/checkout@v2
12
13  - id: vars
14    run: |
15      if [ '${{ github.ref }}' == 'refs/heads/master' ]; then echo "::set-output name=environment::prod_stackstream" ; echo "::set-output name=api-url::api" ; elif [ '${{ github.ref }}' == 'refs/heads/staging' ]; then echo "::set-output name=environment::staging_stackstream"  ; echo "::set-output name=api-url::stagingapi" ; else echo "::set-output name=environment::dev_stackstream" ; echo "::set-output name=api-url::devapi" ; fi
16
17  - uses: pCYSl5EDgo/cat@master
18    id: slack
19    with:
20      path: .github/workflows/slack.txt
21
22  - name: Slack Start Notification
23    uses: 8398a7/action-slack@v3
24    env:
25      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
26      ENVIRONMENT: '`${{ steps.vars.outputs.environment }}`'
27      COLOR: good
28      STATUS: '`Started`'
29    with:
30      status: custom
31      fields: workflow,job,commit,repo,ref,author,took
32      custom_payload: |
33        ${{ steps.slack.outputs.text }}
34
35  - name: Installing modules
36    env:
37      REACT_APP_API_URL: 'https://${{ steps.vars.outputs.api-url }}mergestack.com/api/v1'
38    run: yarn install
39
40  - name: Create Frontend Build
41    env:
42      REACT_APP_API_URL: 'https://${{ steps.vars.outputs.api-url }}mergestack.com/api/v1'
43    run: yarn build
44
45  - name: Deploy to Frontend Server DEV
46    if: ${{ contains(github.ref, 'dev') }}
47    uses: easingthemes/ssh-deploy@v2.1.5
48    env:
49      SSH_PRIVATE_KEY: ${{ secrets.DEV_KEY }}
50      ARGS: '-rltgoDzvO --delete'
51      SOURCE: 'deploy/'
52      REMOTE_HOST: ${{ secrets.DEV_HOST }}
53      REMOTE_USER: plyfolio-dev
54      TARGET: '/home/plyfolio-dev/${{ steps.vars.outputs.environment }}/fe/deploy'
55   {
56  "name": "stackstream-fe",
57  "version": "1.0.0",
58  "authors": [
59    "fayyaznofal@gmail.com"
60  ],
61  "private": true,
62  "dependencies": {
63    "@fortawesome/fontawesome-svg-core": "^1.2.34",
64    "@fortawesome/free-solid-svg-icons": "^5.15.2",
65    "@fortawesome/react-fontawesome": "^0.1.14",
66    "@fullcalendar/bootstrap": "^5.5.0",
67    "@fullcalendar/core": "^5.5.0",
68    "@fullcalendar/daygrid": "^5.5.0",
69    "@fullcalendar/interaction": "^5.5.0",
70    "@fullcalendar/react": "^5.5.0",
71    "@lourenci/react-kanban": "^2.1.0",
72    "@redux-saga/simple-saga-monitor": "^1.1.2",
73    "@testing-library/jest-dom": "^5.11.9",
74    "@testing-library/react": "^11.2.3",
75    "@testing-library/user-event": "^12.6.0",
76    "@toast-ui/react-chart": "^1.0.2",
77    "@types/jest": "^26.0.14",
78    "@types/node": "^14.10.3",
79    "@types/react": "^16.9.49",
80    "@types/react-dom": "^16.9.8",
81    "@vtaits/react-color-picker": "^0.1.1",
82    "apexcharts": "^3.23.1",
83    "availity-reactstrap-validation": "^2.7.0",
84    "axios": "^0.21.1",
85    "axios-mock-adapter": "^1.19.0",
86    "axios-progress-bar": "^1.2.0",
87    "bootstrap": "^5.0.0-beta2",
88    "chart.js": "^2.9.4",
89    "chartist": "^0.11.4",
90    "classnames": "^2.2.6",
91    "components": "^0.1.0",
92    "dotenv": "^8.2.0",
93    "draft-js": "^0.11.7",
94    "echarts": "^4.9.0",
95    "echarts-for-react": "^2.0.16",
96    "firebase": "^8.2.3",
97    "google-maps-react": "^2.0.6",
98    "history": "^4.10.1",
99    "i": "^0.3.6",
100    "i18next": "^19.8.4",
101    "i18next-browser-languagedetector": "^6.0.1",
102    "jsonwebtoken": "^8.5.1",
103    "leaflet": "^1.7.1",
104    "lodash": "^4.17.21",
105    "lodash.clonedeep": "^4.5.0",
106    "lodash.get": "^4.4.2",
107    "metismenujs": "^1.2.1",
108    "mkdirp": "^1.0.4",
109    "moment": "2.29.1",
110    "moment-timezone": "^0.5.32",
111    "nouislider-react": "^3.3.9",
112    "npm": "^7.6.3",
113    "prop-types": "^15.7.2",
114    "query-string": "^6.14.0",
115    "react": "^16.13.1",
116    "react-apexcharts": "^1.3.7",
117    "react-auth-code-input": "^1.0.0",
118    "react-avatar": "^3.10.0",
119    "react-bootstrap": "^1.5.0",
120    "react-bootstrap-editable": "^0.8.2",
121    "react-bootstrap-sweetalert": "^5.2.0",
122    "react-bootstrap-table-next": "^4.0.3",
123    "react-bootstrap-table2-editor": "^1.4.0",
124    "react-bootstrap-table2-paginator": "^2.1.2",
125    "react-bootstrap-table2-toolkit": "^2.1.3",
126    "react-chartist": "^0.14.3",
127    "react-chartjs-2": "^2.11.1",
128    "react-color": "^2.19.3",
129    "react-confirm-alert": "^2.7.0",
130    "react-content-loader": "^6.0.1",
131    "react-countdown": "^2.3.1",
132    "react-countup": "^4.3.3",
133    "react-cropper": "^2.1.4",
134    "react-data-table-component": "^6.11.8",
135    "react-date-picker": "^8.0.6",
136    "react-datepicker": "^3.4.1",
137    "react-dom": "^16.13.1",
138    "react-draft-wysiwyg": "^1.14.5",
139    "react-drag-listview": "^0.1.8",
140    "react-drawer": "^1.3.4",
141    "react-dropzone": "^11.2.4",
142    "react-dual-listbox": "^2.0.0",
143    "react-facebook-login": "^4.1.1",
144    "react-flatpickr": "^3.10.6",
145    "react-google-login": "^5.2.2",
146    "react-hook-form": "^7.15.2",
147    "react-i18next": "^11.8.5",
148    "react-icons": "^4.2.0",
149    "react-image-lightbox": "^5.1.1",
150    "react-input-mask": "^2.0.4",
151    "react-jvectormap": "^0.0.16",
152    "react-leaflet": "^3.0.5",
153    "react-meta-tags": "^1.0.1",
154    "react-modal-video": "^1.2.6",
155    "react-notifications": "^1.7.2",
156    "react-number-format": "^4.7.3",
157    "react-perfect-scrollbar": "^1.5.8",
158    "react-rangeslider": "^2.2.0",
159    "react-rating": "^2.0.5",
160    "react-rating-tooltip": "^1.1.6",
161    "react-redux": "^7.2.1",
162    "react-responsive-carousel": "^3.2.11",
163    "react-router-dom": "^5.2.0",
164    "react-script": "^2.0.5",
165    "react-scripts": "3.4.3",
166    "react-select": "^4.3.1",
167    "react-sparklines": "^1.7.0",
168    "react-star-ratings": "^2.3.0",
169    "react-super-responsive-table": "^5.2.0",
170    "react-switch": "^6.0.0",
171    "react-table": "^7.6.3",
172    "react-toastify": "^7.0.3",
173    "react-toastr": "^3.0.0",
174    "react-twitter-auth": "0.0.13",
175    "reactstrap": "^8.8.1",
176    "recharts": "^2.0.8",
177    "redux": "^4.0.5",
178    "redux-saga": "^1.1.3",
179    "reselect": "^4.0.0",
180    "sass": "^1.37.5",
181    "simplebar-react": "^2.3.0",
182    "styled": "^1.0.0",
183    "styled-components": "^5.2.1",
184    "toastr": "^2.1.4",
185    "typescript": "^4.0.2",
186    "universal-cookie": "^4.0.4"
187  },
188  "devDependencies": {
189    "@typescript-eslint/eslint-plugin": "^2.27.0",
190    "@typescript-eslint/parser": "^2.27.0",
191    "@typescript-eslint/typescript-estree": "^4.15.2",
192    "eslint-config-prettier": "^6.10.1",
193    "eslint-plugin-prettier": "^3.1.2",
194    "husky": "^4.2.5",
195    "lint-staged": "^10.1.3",
196    "prettier": "^1.19.1",
197    "react-test-renderer": "^16.13.1",
198    "redux-devtools-extension": "^2.13.8",
199    "redux-mock-store": "^1.5.4"
200  },
201  "scripts": {
202    "start": "react-scripts start",
203    "build": "react-scripts build && mv build ./deploy/build",
204    "build-local": "react-scripts build",
205    "test": "react-scripts test",
206    "eject": "react-scripts eject"
207  },
208  "eslintConfig": {
209    "extends": "react-app"
210  },
211  "husky": {
212    "hooks": {
213      "pre-commit": "lint-staged"
214    }
215  },
216  "lint-staged": {
217    "*.{js,ts,tsx}": [
218      "eslint --fix"
219    ]
220  },
221  "browserslist": {
222    "production": [
223      ">0.2%",
224      "not dead",
225      "not op_mini all"
226    ],
227    "development": [
228      "last 1 chrome version",
229      "last 1 firefox version",
230      "last 1 safari version"
231    ]
232  }
233}
234

ANSWER

Answered 2022-Mar-16 at 07:01

First, this error message is indeed expected on Jan. 11th, 2022.
See "Improving Git protocol security on GitHub".

January 11, 2022 Final brownout.

This is the full brownout period where we’ll temporarily stop accepting the deprecated key and signature types, ciphers, and MACs, and the unencrypted Git protocol.
This will help clients discover any lingering use of older keys or old URLs.

Second, check your package.json dependencies for any git:// URL, as in this example, fixed in this PR.

As noted by JΓΆrg W Mittag:

There was a 4-month warning.
The entire Internet has been moving away from unauthenticated, unencrypted protocols for a decade, it's not like this is a huge surprise.

Personally, I consider it less an "issue" and more "detecting unmaintained dependencies".

Plus, this is still only the brownout period, so the protocol will only be disabled for a short period of time, allowing developers to discover the problem.

The permanent shutdown is not until March 15th.


For GitHub Actions:

As in actions/checkout issue 14, you can add as a first step:

1Command: git
2Arguments: ls-remote --tags --heads git://github.com/adobe-webplatform/eve.git
3Directory: /home/runner/work/stackstream-fe/stackstream-fe
4Output:
5fatal: remote error: 
6  The unauthenticated git protocol on port 9418 is no longer supported.
7    - name: Installing modules
8      run: yarn install
9  steps:
10  - name: Checkout
11    uses: actions/checkout@v2
12
13  - id: vars
14    run: |
15      if [ '${{ github.ref }}' == 'refs/heads/master' ]; then echo "::set-output name=environment::prod_stackstream" ; echo "::set-output name=api-url::api" ; elif [ '${{ github.ref }}' == 'refs/heads/staging' ]; then echo "::set-output name=environment::staging_stackstream"  ; echo "::set-output name=api-url::stagingapi" ; else echo "::set-output name=environment::dev_stackstream" ; echo "::set-output name=api-url::devapi" ; fi
16
17  - uses: pCYSl5EDgo/cat@master
18    id: slack
19    with:
20      path: .github/workflows/slack.txt
21
22  - name: Slack Start Notification
23    uses: 8398a7/action-slack@v3
24    env:
25      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
26      ENVIRONMENT: '`${{ steps.vars.outputs.environment }}`'
27      COLOR: good
28      STATUS: '`Started`'
29    with:
30      status: custom
31      fields: workflow,job,commit,repo,ref,author,took
32      custom_payload: |
33        ${{ steps.slack.outputs.text }}
34
35  - name: Installing modules
36    env:
37      REACT_APP_API_URL: 'https://${{ steps.vars.outputs.api-url }}mergestack.com/api/v1'
38    run: yarn install
39
40  - name: Create Frontend Build
41    env:
42      REACT_APP_API_URL: 'https://${{ steps.vars.outputs.api-url }}mergestack.com/api/v1'
43    run: yarn build
44
45  - name: Deploy to Frontend Server DEV
46    if: ${{ contains(github.ref, 'dev') }}
47    uses: easingthemes/ssh-deploy@v2.1.5
48    env:
49      SSH_PRIVATE_KEY: ${{ secrets.DEV_KEY }}
50      ARGS: '-rltgoDzvO --delete'
51      SOURCE: 'deploy/'
52      REMOTE_HOST: ${{ secrets.DEV_HOST }}
53      REMOTE_USER: plyfolio-dev
54      TARGET: '/home/plyfolio-dev/${{ steps.vars.outputs.environment }}/fe/deploy'
55   {
56  "name": "stackstream-fe",
57  "version": "1.0.0",
58  "authors": [
59    "fayyaznofal@gmail.com"
60  ],
61  "private": true,
62  "dependencies": {
63    "@fortawesome/fontawesome-svg-core": "^1.2.34",
64    "@fortawesome/free-solid-svg-icons": "^5.15.2",
65    "@fortawesome/react-fontawesome": "^0.1.14",
66    "@fullcalendar/bootstrap": "^5.5.0",
67    "@fullcalendar/core": "^5.5.0",
68    "@fullcalendar/daygrid": "^5.5.0",
69    "@fullcalendar/interaction": "^5.5.0",
70    "@fullcalendar/react": "^5.5.0",
71    "@lourenci/react-kanban": "^2.1.0",
72    "@redux-saga/simple-saga-monitor": "^1.1.2",
73    "@testing-library/jest-dom": "^5.11.9",
74    "@testing-library/react": "^11.2.3",
75    "@testing-library/user-event": "^12.6.0",
76    "@toast-ui/react-chart": "^1.0.2",
77    "@types/jest": "^26.0.14",
78    "@types/node": "^14.10.3",
79    "@types/react": "^16.9.49",
80    "@types/react-dom": "^16.9.8",
81    "@vtaits/react-color-picker": "^0.1.1",
82    "apexcharts": "^3.23.1",
83    "availity-reactstrap-validation": "^2.7.0",
84    "axios": "^0.21.1",
85    "axios-mock-adapter": "^1.19.0",
86    "axios-progress-bar": "^1.2.0",
87    "bootstrap": "^5.0.0-beta2",
88    "chart.js": "^2.9.4",
89    "chartist": "^0.11.4",
90    "classnames": "^2.2.6",
91    "components": "^0.1.0",
92    "dotenv": "^8.2.0",
93    "draft-js": "^0.11.7",
94    "echarts": "^4.9.0",
95    "echarts-for-react": "^2.0.16",
96    "firebase": "^8.2.3",
97    "google-maps-react": "^2.0.6",
98    "history": "^4.10.1",
99    "i": "^0.3.6",
100    "i18next": "^19.8.4",
101    "i18next-browser-languagedetector": "^6.0.1",
102    "jsonwebtoken": "^8.5.1",
103    "leaflet": "^1.7.1",
104    "lodash": "^4.17.21",
105    "lodash.clonedeep": "^4.5.0",
106    "lodash.get": "^4.4.2",
107    "metismenujs": "^1.2.1",
108    "mkdirp": "^1.0.4",
109    "moment": "2.29.1",
110    "moment-timezone": "^0.5.32",
111    "nouislider-react": "^3.3.9",
112    "npm": "^7.6.3",
113    "prop-types": "^15.7.2",
114    "query-string": "^6.14.0",
115    "react": "^16.13.1",
116    "react-apexcharts": "^1.3.7",
117    "react-auth-code-input": "^1.0.0",
118    "react-avatar": "^3.10.0",
119    "react-bootstrap": "^1.5.0",
120    "react-bootstrap-editable": "^0.8.2",
121    "react-bootstrap-sweetalert": "^5.2.0",
122    "react-bootstrap-table-next": "^4.0.3",
123    "react-bootstrap-table2-editor": "^1.4.0",
124    "react-bootstrap-table2-paginator": "^2.1.2",
125    "react-bootstrap-table2-toolkit": "^2.1.3",
126    "react-chartist": "^0.14.3",
127    "react-chartjs-2": "^2.11.1",
128    "react-color": "^2.19.3",
129    "react-confirm-alert": "^2.7.0",
130    "react-content-loader": "^6.0.1",
131    "react-countdown": "^2.3.1",
132    "react-countup": "^4.3.3",
133    "react-cropper": "^2.1.4",
134    "react-data-table-component": "^6.11.8",
135    "react-date-picker": "^8.0.6",
136    "react-datepicker": "^3.4.1",
137    "react-dom": "^16.13.1",
138    "react-draft-wysiwyg": "^1.14.5",
139    "react-drag-listview": "^0.1.8",
140    "react-drawer": "^1.3.4",
141    "react-dropzone": "^11.2.4",
142    "react-dual-listbox": "^2.0.0",
143    "react-facebook-login": "^4.1.1",
144    "react-flatpickr": "^3.10.6",
145    "react-google-login": "^5.2.2",
146    "react-hook-form": "^7.15.2",
147    "react-i18next": "^11.8.5",
148    "react-icons": "^4.2.0",
149    "react-image-lightbox": "^5.1.1",
150    "react-input-mask": "^2.0.4",
151    "react-jvectormap": "^0.0.16",
152    "react-leaflet": "^3.0.5",
153    "react-meta-tags": "^1.0.1",
154    "react-modal-video": "^1.2.6",
155    "react-notifications": "^1.7.2",
156    "react-number-format": "^4.7.3",
157    "react-perfect-scrollbar": "^1.5.8",
158    "react-rangeslider": "^2.2.0",
159    "react-rating": "^2.0.5",
160    "react-rating-tooltip": "^1.1.6",
161    "react-redux": "^7.2.1",
162    "react-responsive-carousel": "^3.2.11",
163    "react-router-dom": "^5.2.0",
164    "react-script": "^2.0.5",
165    "react-scripts": "3.4.3",
166    "react-select": "^4.3.1",
167    "react-sparklines": "^1.7.0",
168    "react-star-ratings": "^2.3.0",
169    "react-super-responsive-table": "^5.2.0",
170    "react-switch": "^6.0.0",
171    "react-table": "^7.6.3",
172    "react-toastify": "^7.0.3",
173    "react-toastr": "^3.0.0",
174    "react-twitter-auth": "0.0.13",
175    "reactstrap": "^8.8.1",
176    "recharts": "^2.0.8",
177    "redux": "^4.0.5",
178    "redux-saga": "^1.1.3",
179    "reselect": "^4.0.0",
180    "sass": "^1.37.5",
181    "simplebar-react": "^2.3.0",
182    "styled": "^1.0.0",
183    "styled-components": "^5.2.1",
184    "toastr": "^2.1.4",
185    "typescript": "^4.0.2",
186    "universal-cookie": "^4.0.4"
187  },
188  "devDependencies": {
189    "@typescript-eslint/eslint-plugin": "^2.27.0",
190    "@typescript-eslint/parser": "^2.27.0",
191    "@typescript-eslint/typescript-estree": "^4.15.2",
192    "eslint-config-prettier": "^6.10.1",
193    "eslint-plugin-prettier": "^3.1.2",
194    "husky": "^4.2.5",
195    "lint-staged": "^10.1.3",
196    "prettier": "^1.19.1",
197    "react-test-renderer": "^16.13.1",
198    "redux-devtools-extension": "^2.13.8",
199    "redux-mock-store": "^1.5.4"
200  },
201  "scripts": {
202    "start": "react-scripts start",
203    "build": "react-scripts build && mv build ./deploy/build",
204    "build-local": "react-scripts build",
205    "test": "react-scripts test",
206    "eject": "react-scripts eject"
207  },
208  "eslintConfig": {
209    "extends": "react-app"
210  },
211  "husky": {
212    "hooks": {
213      "pre-commit": "lint-staged"
214    }
215  },
216  "lint-staged": {
217    "*.{js,ts,tsx}": [
218      "eslint --fix"
219    ]
220  },
221  "browserslist": {
222    "production": [
223      ">0.2%",
224      "not dead",
225      "not op_mini all"
226    ],
227    "development": [
228      "last 1 chrome version",
229      "last 1 firefox version",
230      "last 1 safari version"
231    ]
232  }
233}
234    - name: Fix up git URLs
235      run: echo -e '[url "https://github.com/"]\n  insteadOf = "git://github.com/"' >> ~/.gitconfig
236

That will change any git://github.com/ into https://github.com/.

For local projects

For all your repositories, you can set:

1Command: git
2Arguments: ls-remote --tags --heads git://github.com/adobe-webplatform/eve.git
3Directory: /home/runner/work/stackstream-fe/stackstream-fe
4Output:
5fatal: remote error: 
6  The unauthenticated git protocol on port 9418 is no longer supported.
7    - name: Installing modules
8      run: yarn install
9  steps:
10  - name: Checkout
11    uses: actions/checkout@v2
12
13  - id: vars
14    run: |
15      if [ '${{ github.ref }}' == 'refs/heads/master' ]; then echo "::set-output name=environment::prod_stackstream" ; echo "::set-output name=api-url::api" ; elif [ '${{ github.ref }}' == 'refs/heads/staging' ]; then echo "::set-output name=environment::staging_stackstream"  ; echo "::set-output name=api-url::stagingapi" ; else echo "::set-output name=environment::dev_stackstream" ; echo "::set-output name=api-url::devapi" ; fi
16
17  - uses: pCYSl5EDgo/cat@master
18    id: slack
19    with:
20      path: .github/workflows/slack.txt
21
22  - name: Slack Start Notification
23    uses: 8398a7/action-slack@v3
24    env:
25      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
26      ENVIRONMENT: '`${{ steps.vars.outputs.environment }}`'
27      COLOR: good
28      STATUS: '`Started`'
29    with:
30      status: custom
31      fields: workflow,job,commit,repo,ref,author,took
32      custom_payload: |
33        ${{ steps.slack.outputs.text }}
34
35  - name: Installing modules
36    env:
37      REACT_APP_API_URL: 'https://${{ steps.vars.outputs.api-url }}mergestack.com/api/v1'
38    run: yarn install
39
40  - name: Create Frontend Build
41    env:
42      REACT_APP_API_URL: 'https://${{ steps.vars.outputs.api-url }}mergestack.com/api/v1'
43    run: yarn build
44
45  - name: Deploy to Frontend Server DEV
46    if: ${{ contains(github.ref, 'dev') }}
47    uses: easingthemes/ssh-deploy@v2.1.5
48    env:
49      SSH_PRIVATE_KEY: ${{ secrets.DEV_KEY }}
50      ARGS: '-rltgoDzvO --delete'
51      SOURCE: 'deploy/'
52      REMOTE_HOST: ${{ secrets.DEV_HOST }}
53      REMOTE_USER: plyfolio-dev
54      TARGET: '/home/plyfolio-dev/${{ steps.vars.outputs.environment }}/fe/deploy'
55   {
56  "name": "stackstream-fe",
57  "version": "1.0.0",
58  "authors": [
59    "fayyaznofal@gmail.com"
60  ],
61  "private": true,
62  "dependencies": {
63    "@fortawesome/fontawesome-svg-core": "^1.2.34",
64    "@fortawesome/free-solid-svg-icons": "^5.15.2",
65    "@fortawesome/react-fontawesome": "^0.1.14",
66    "@fullcalendar/bootstrap": "^5.5.0",
67    "@fullcalendar/core": "^5.5.0",
68    "@fullcalendar/daygrid": "^5.5.0",
69    "@fullcalendar/interaction": "^5.5.0",
70    "@fullcalendar/react": "^5.5.0",
71    "@lourenci/react-kanban": "^2.1.0",
72    "@redux-saga/simple-saga-monitor": "^1.1.2",
73    "@testing-library/jest-dom": "^5.11.9",
74    "@testing-library/react": "^11.2.3",
75    "@testing-library/user-event": "^12.6.0",
76    "@toast-ui/react-chart": "^1.0.2",
77    "@types/jest": "^26.0.14",
78    "@types/node": "^14.10.3",
79    "@types/react": "^16.9.49",
80    "@types/react-dom": "^16.9.8",
81    "@vtaits/react-color-picker": "^0.1.1",
82    "apexcharts": "^3.23.1",
83    "availity-reactstrap-validation": "^2.7.0",
84    "axios": "^0.21.1",
85    "axios-mock-adapter": "^1.19.0",
86    "axios-progress-bar": "^1.2.0",
87    "bootstrap": "^5.0.0-beta2",
88    "chart.js": "^2.9.4",
89    "chartist": "^0.11.4",
90    "classnames": "^2.2.6",
91    "components": "^0.1.0",
92    "dotenv": "^8.2.0",
93    "draft-js": "^0.11.7",
94    "echarts": "^4.9.0",
95    "echarts-for-react": "^2.0.16",
96    "firebase": "^8.2.3",
97    "google-maps-react": "^2.0.6",
98    "history": "^4.10.1",
99    "i": "^0.3.6",
100    "i18next": "^19.8.4",
101    "i18next-browser-languagedetector": "^6.0.1",
102    "jsonwebtoken": "^8.5.1",
103    "leaflet": "^1.7.1",
104    "lodash": "^4.17.21",
105    "lodash.clonedeep": "^4.5.0",
106    "lodash.get": "^4.4.2",
107    "metismenujs": "^1.2.1",
108    "mkdirp": "^1.0.4",
109    "moment": "2.29.1",
110    "moment-timezone": "^0.5.32",
111    "nouislider-react": "^3.3.9",
112    "npm": "^7.6.3",
113    "prop-types": "^15.7.2",
114    "query-string": "^6.14.0",
115    "react": "^16.13.1",
116    "react-apexcharts": "^1.3.7",
117    "react-auth-code-input": "^1.0.0",
118    "react-avatar": "^3.10.0",
119    "react-bootstrap": "^1.5.0",
120    "react-bootstrap-editable": "^0.8.2",
121    "react-bootstrap-sweetalert": "^5.2.0",
122    "react-bootstrap-table-next": "^4.0.3",
123    "react-bootstrap-table2-editor": "^1.4.0",
124    "react-bootstrap-table2-paginator": "^2.1.2",
125    "react-bootstrap-table2-toolkit": "^2.1.3",
126    "react-chartist": "^0.14.3",
127    "react-chartjs-2": "^2.11.1",
128    "react-color": "^2.19.3",
129    "react-confirm-alert": "^2.7.0",
130    "react-content-loader": "^6.0.1",
131    "react-countdown": "^2.3.1",
132    "react-countup": "^4.3.3",
133    "react-cropper": "^2.1.4",
134    "react-data-table-component": "^6.11.8",
135    "react-date-picker": "^8.0.6",
136    "react-datepicker": "^3.4.1",
137    "react-dom": "^16.13.1",
138    "react-draft-wysiwyg": "^1.14.5",
139    "react-drag-listview": "^0.1.8",
140    "react-drawer": "^1.3.4",
141    "react-dropzone": "^11.2.4",
142    "react-dual-listbox": "^2.0.0",
143    "react-facebook-login": "^4.1.1",
144    "react-flatpickr": "^3.10.6",
145    "react-google-login": "^5.2.2",
146    "react-hook-form": "^7.15.2",
147    "react-i18next": "^11.8.5",
148    "react-icons": "^4.2.0",
149    "react-image-lightbox": "^5.1.1",
150    "react-input-mask": "^2.0.4",
151    "react-jvectormap": "^0.0.16",
152    "react-leaflet": "^3.0.5",
153    "react-meta-tags": "^1.0.1",
154    "react-modal-video": "^1.2.6",
155    "react-notifications": "^1.7.2",
156    "react-number-format": "^4.7.3",
157    "react-perfect-scrollbar": "^1.5.8",
158    "react-rangeslider": "^2.2.0",
159    "react-rating": "^2.0.5",
160    "react-rating-tooltip": "^1.1.6",
161    "react-redux": "^7.2.1",
162    "react-responsive-carousel": "^3.2.11",
163    "react-router-dom": "^5.2.0",
164    "react-script": "^2.0.5",
165    "react-scripts": "3.4.3",
166    "react-select": "^4.3.1",
167    "react-sparklines": "^1.7.0",
168    "react-star-ratings": "^2.3.0",
169    "react-super-responsive-table": "^5.2.0",
170    "react-switch": "^6.0.0",
171    "react-table": "^7.6.3",
172    "react-toastify": "^7.0.3",
173    "react-toastr": "^3.0.0",
174    "react-twitter-auth": "0.0.13",
175    "reactstrap": "^8.8.1",
176    "recharts": "^2.0.8",
177    "redux": "^4.0.5",
178    "redux-saga": "^1.1.3",
179    "reselect": "^4.0.0",
180    "sass": "^1.37.5",
181    "simplebar-react": "^2.3.0",
182    "styled": "^1.0.0",
183    "styled-components": "^5.2.1",
184    "toastr": "^2.1.4",
185    "typescript": "^4.0.2",
186    "universal-cookie": "^4.0.4"
187  },
188  "devDependencies": {
189    "@typescript-eslint/eslint-plugin": "^2.27.0",
190    "@typescript-eslint/parser": "^2.27.0",
191    "@typescript-eslint/typescript-estree": "^4.15.2",
192    "eslint-config-prettier": "^6.10.1",
193    "eslint-plugin-prettier": "^3.1.2",
194    "husky": "^4.2.5",
195    "lint-staged": "^10.1.3",
196    "prettier": "^1.19.1",
197    "react-test-renderer": "^16.13.1",
198    "redux-devtools-extension": "^2.13.8",
199    "redux-mock-store": "^1.5.4"
200  },
201  "scripts": {
202    "start": "react-scripts start",
203    "build": "react-scripts build && mv build ./deploy/build",
204    "build-local": "react-scripts build",
205    "test": "react-scripts test",
206    "eject": "react-scripts eject"
207  },
208  "eslintConfig": {
209    "extends": "react-app"
210  },
211  "husky": {
212    "hooks": {
213      "pre-commit": "lint-staged"
214    }
215  },
216  "lint-staged": {
217    "*.{js,ts,tsx}": [
218      "eslint --fix"
219    ]
220  },
221  "browserslist": {
222    "production": [
223      ">0.2%",
224      "not dead",
225      "not op_mini all"
226    ],
227    "development": [
228      "last 1 chrome version",
229      "last 1 firefox version",
230      "last 1 safari version"
231    ]
232  }
233}
234    - name: Fix up git URLs
235      run: echo -e '[url "https://github.com/"]\n  insteadOf = "git://github.com/"' >> ~/.gitconfig
236git config --global url."https://github.com/".insteadOf git://github.com/
237

You can also use SSH, but GitHub Security reminds us that, as of March 15th, 2022, GitHub stopped accepting DSA keys. RSA keys uploaded after Nov 2, 2021 will work only with SHA-2 signatures.
The deprecated MACs, ciphers, and unencrypted Git protocol are permanently disabled.

So this (with the right key) would work:

1Command: git
2Arguments: ls-remote --tags --heads git://github.com/adobe-webplatform/eve.git
3Directory: /home/runner/work/stackstream-fe/stackstream-fe
4Output:
5fatal: remote error: 
6  The unauthenticated git protocol on port 9418 is no longer supported.
7    - name: Installing modules
8      run: yarn install
9  steps:
10  - name: Checkout
11    uses: actions/checkout@v2
12
13  - id: vars
14    run: |
15      if [ '${{ github.ref }}' == 'refs/heads/master' ]; then echo "::set-output name=environment::prod_stackstream" ; echo "::set-output name=api-url::api" ; elif [ '${{ github.ref }}' == 'refs/heads/staging' ]; then echo "::set-output name=environment::staging_stackstream"  ; echo "::set-output name=api-url::stagingapi" ; else echo "::set-output name=environment::dev_stackstream" ; echo "::set-output name=api-url::devapi" ; fi
16
17  - uses: pCYSl5EDgo/cat@master
18    id: slack
19    with:
20      path: .github/workflows/slack.txt
21
22  - name: Slack Start Notification
23    uses: 8398a7/action-slack@v3
24    env:
25      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
26      ENVIRONMENT: '`${{ steps.vars.outputs.environment }}`'
27      COLOR: good
28      STATUS: '`Started`'
29    with:
30      status: custom
31      fields: workflow,job,commit,repo,ref,author,took
32      custom_payload: |
33        ${{ steps.slack.outputs.text }}
34
35  - name: Installing modules
36    env:
37      REACT_APP_API_URL: 'https://${{ steps.vars.outputs.api-url }}mergestack.com/api/v1'
38    run: yarn install
39
40  - name: Create Frontend Build
41    env:
42      REACT_APP_API_URL: 'https://${{ steps.vars.outputs.api-url }}mergestack.com/api/v1'
43    run: yarn build
44
45  - name: Deploy to Frontend Server DEV
46    if: ${{ contains(github.ref, 'dev') }}
47    uses: easingthemes/ssh-deploy@v2.1.5
48    env:
49      SSH_PRIVATE_KEY: ${{ secrets.DEV_KEY }}
50      ARGS: '-rltgoDzvO --delete'
51      SOURCE: 'deploy/'
52      REMOTE_HOST: ${{ secrets.DEV_HOST }}
53      REMOTE_USER: plyfolio-dev
54      TARGET: '/home/plyfolio-dev/${{ steps.vars.outputs.environment }}/fe/deploy'
55   {
56  "name": "stackstream-fe",
57  "version": "1.0.0",
58  "authors": [
59    "fayyaznofal@gmail.com"
60  ],
61  "private": true,
62  "dependencies": {
63    "@fortawesome/fontawesome-svg-core": "^1.2.34",
64    "@fortawesome/free-solid-svg-icons": "^5.15.2",
65    "@fortawesome/react-fontawesome": "^0.1.14",
66    "@fullcalendar/bootstrap": "^5.5.0",
67    "@fullcalendar/core": "^5.5.0",
68    "@fullcalendar/daygrid": "^5.5.0",
69    "@fullcalendar/interaction": "^5.5.0",
70    "@fullcalendar/react": "^5.5.0",
71    "@lourenci/react-kanban": "^2.1.0",
72    "@redux-saga/simple-saga-monitor": "^1.1.2",
73    "@testing-library/jest-dom": "^5.11.9",
74    "@testing-library/react": "^11.2.3",
75    "@testing-library/user-event": "^12.6.0",
76    "@toast-ui/react-chart": "^1.0.2",
77    "@types/jest": "^26.0.14",
78    "@types/node": "^14.10.3",
79    "@types/react": "^16.9.49",
80    "@types/react-dom": "^16.9.8",
81    "@vtaits/react-color-picker": "^0.1.1",
82    "apexcharts": "^3.23.1",
83    "availity-reactstrap-validation": "^2.7.0",
84    "axios": "^0.21.1",
85    "axios-mock-adapter": "^1.19.0",
86    "axios-progress-bar": "^1.2.0",
87    "bootstrap": "^5.0.0-beta2",
88    "chart.js": "^2.9.4",
89    "chartist": "^0.11.4",
90    "classnames": "^2.2.6",
91    "components": "^0.1.0",
92    "dotenv": "^8.2.0",
93    "draft-js": "^0.11.7",
94    "echarts": "^4.9.0",
95    "echarts-for-react": "^2.0.16",
96    "firebase": "^8.2.3",
97    "google-maps-react": "^2.0.6",
98    "history": "^4.10.1",
99    "i": "^0.3.6",
100    "i18next": "^19.8.4",
101    "i18next-browser-languagedetector": "^6.0.1",
102    "jsonwebtoken": "^8.5.1",
103    "leaflet": "^1.7.1",
104    "lodash": "^4.17.21",
105    "lodash.clonedeep": "^4.5.0",
106    "lodash.get": "^4.4.2",
107    "metismenujs": "^1.2.1",
108    "mkdirp": "^1.0.4",
109    "moment": "2.29.1",
110    "moment-timezone": "^0.5.32",
111    "nouislider-react": "^3.3.9",
112    "npm": "^7.6.3",
113    "prop-types": "^15.7.2",
114    "query-string": "^6.14.0",
115    "react": "^16.13.1",
116    "react-apexcharts": "^1.3.7",
117    "react-auth-code-input": "^1.0.0",
118    "react-avatar": "^3.10.0",
119    "react-bootstrap": "^1.5.0",
120    "react-bootstrap-editable": "^0.8.2",
121    "react-bootstrap-sweetalert": "^5.2.0",
122    "react-bootstrap-table-next": "^4.0.3",
123    "react-bootstrap-table2-editor": "^1.4.0",
124    "react-bootstrap-table2-paginator": "^2.1.2",
125    "react-bootstrap-table2-toolkit": "^2.1.3",
126    "react-chartist": "^0.14.3",
127    "react-chartjs-2": "^2.11.1",
128    "react-color": "^2.19.3",
129    "react-confirm-alert": "^2.7.0",
130    "react-content-loader": "^6.0.1",
131    "react-countdown": "^2.3.1",
132    "react-countup": "^4.3.3",
133    "react-cropper": "^2.1.4",
134    "react-data-table-component": "^6.11.8",
135    "react-date-picker": "^8.0.6",
136    "react-datepicker": "^3.4.1",
137    "react-dom": "^16.13.1",
138    "react-draft-wysiwyg": "^1.14.5",
139    "react-drag-listview": "^0.1.8",
140    "react-drawer": "^1.3.4",
141    "react-dropzone": "^11.2.4",
142    "react-dual-listbox": "^2.0.0",
143    "react-facebook-login": "^4.1.1",
144    "react-flatpickr": "^3.10.6",
145    "react-google-login": "^5.2.2",
146    "react-hook-form": "^7.15.2",
147    "react-i18next": "^11.8.5",
148    "react-icons": "^4.2.0",
149    "react-image-lightbox": "^5.1.1",
150    "react-input-mask": "^2.0.4",
151    "react-jvectormap": "^0.0.16",
152    "react-leaflet": "^3.0.5",
153    "react-meta-tags": "^1.0.1",
154    "react-modal-video": "^1.2.6",
155    "react-notifications": "^1.7.2",
156    "react-number-format": "^4.7.3",
157    "react-perfect-scrollbar": "^1.5.8",
158    "react-rangeslider": "^2.2.0",
159    "react-rating": "^2.0.5",
160    "react-rating-tooltip": "^1.1.6",
161    "react-redux": "^7.2.1",
162    "react-responsive-carousel": "^3.2.11",
163    "react-router-dom": "^5.2.0",
164    "react-script": "^2.0.5",
165    "react-scripts": "3.4.3",
166    "react-select": "^4.3.1",
167    "react-sparklines": "^1.7.0",
168    "react-star-ratings": "^2.3.0",
169    "react-super-responsive-table": "^5.2.0",
170    "react-switch": "^6.0.0",
171    "react-table": "^7.6.3",
172    "react-toastify": "^7.0.3",
173    "react-toastr": "^3.0.0",
174    "react-twitter-auth": "0.0.13",
175    "reactstrap": "^8.8.1",
176    "recharts": "^2.0.8",
177    "redux": "^4.0.5",
178    "redux-saga": "^1.1.3",
179    "reselect": "^4.0.0",
180    "sass": "^1.37.5",
181    "simplebar-react": "^2.3.0",
182    "styled": "^1.0.0",
183    "styled-components": "^5.2.1",
184    "toastr": "^2.1.4",
185    "typescript": "^4.0.2",
186    "universal-cookie": "^4.0.4"
187  },
188  "devDependencies": {
189    "@typescript-eslint/eslint-plugin": "^2.27.0",
190    "@typescript-eslint/parser": "^2.27.0",
191    "@typescript-eslint/typescript-estree": "^4.15.2",
192    "eslint-config-prettier": "^6.10.1",
193    "eslint-plugin-prettier": "^3.1.2",
194    "husky": "^4.2.5",
195    "lint-staged": "^10.1.3",
196    "prettier": "^1.19.1",
197    "react-test-renderer": "^16.13.1",
198    "redux-devtools-extension": "^2.13.8",
199    "redux-mock-store": "^1.5.4"
200  },
201  "scripts": {
202    "start": "react-scripts start",
203    "build": "react-scripts build && mv build ./deploy/build",
204    "build-local": "react-scripts build",
205    "test": "react-scripts test",
206    "eject": "react-scripts eject"
207  },
208  "eslintConfig": {
209    "extends": "react-app"
210  },
211  "husky": {
212    "hooks": {
213      "pre-commit": "lint-staged"
214    }
215  },
216  "lint-staged": {
217    "*.{js,ts,tsx}": [
218      "eslint --fix"
219    ]
220  },
221  "browserslist": {
222    "production": [
223      ">0.2%",
224      "not dead",
225      "not op_mini all"
226    ],
227    "development": [
228      "last 1 chrome version",
229      "last 1 firefox version",
230      "last 1 safari version"
231    ]
232  }
233}
234    - name: Fix up git URLs
235      run: echo -e '[url "https://github.com/"]\n  insteadOf = "git://github.com/"' >> ~/.gitconfig
236git config --global url."https://github.com/".insteadOf git://github.com/
237git config --global url."git@github.com:".insteadOf git://github.com/
238

That will change any git://github.com/ (unencrypted Git protocol) into git@github.com: (SSH URL).

Source https://stackoverflow.com/questions/70663523

QUESTION

Consider using the "jsdom" test environment

Asked 2022-Mar-23 at 20:23

I have this simple test:

1import React from 'react'
2import { render } from '@testing-library/react'
3
4import Button from '.'
5
6describe('Button', () => {
7  it('renders button without crashing', () => {
8    const label = 'test'
9
10    render(<Button label={label} />)
11  })
12})
13
14

And I have a jest.config.json with this content

1import React from 'react'
2import { render } from '@testing-library/react'
3
4import Button from '.'
5
6describe('Button', () => {
7  it('renders button without crashing', () => {
8    const label = 'test'
9
10    render(<Button label={label} />)
11  })
12})
13
14{
15  "setupFilesAfterEnv": [
16    "<rootDir>/lib/settings/setupTests.ts"
17  ]
18}
19

And on my setupTests.ts I have

1import React from 'react'
2import { render } from '@testing-library/react'
3
4import Button from '.'
5
6describe('Button', () => {
7  it('renders button without crashing', () => {
8    const label = 'test'
9
10    render(<Button label={label} />)
11  })
12})
13
14{
15  "setupFilesAfterEnv": [
16    "<rootDir>/lib/settings/setupTests.ts"
17  ]
18}
19import '@testing-library/jest-dom'
20

When I run npm run test (which just run jest), I got the following error:

The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/configuration#testenvironment-string.

Consider using the "jsdom" test environment.

What I am doing wrong? This used to work before an upgrade.

ANSWER

Answered 2021-Oct-25 at 05:17

In your package.json, or jest.config.js/jest.config.js, change the value of the testEnvironment property to jsdom.

Package.json
1import React from 'react'
2import { render } from '@testing-library/react'
3
4import Button from '.'
5
6describe('Button', () => {
7  it('renders button without crashing', () => {
8    const label = 'test'
9
10    render(<Button label={label} />)
11  })
12})
13
14{
15  "setupFilesAfterEnv": [
16    "<rootDir>/lib/settings/setupTests.ts"
17  ]
18}
19import '@testing-library/jest-dom'
20"jest":{
21    "testEnvironment": "jsdom"
22}
23
jest.config.[js|ts]
1import React from 'react'
2import { render } from '@testing-library/react'
3
4import Button from '.'
5
6describe('Button', () => {
7  it('renders button without crashing', () => {
8    const label = 'test'
9
10    render(<Button label={label} />)
11  })
12})
13
14{
15  "setupFilesAfterEnv": [
16    "<rootDir>/lib/settings/setupTests.ts"
17  ]
18}
19import '@testing-library/jest-dom'
20"jest":{
21    "testEnvironment": "jsdom"
22}
23{
24    "testEnvironment": "jsdom"
25}
26
Why?

By default, jest uses the node testEnvironment. This essentially makes any tests meant for a browser environment invalid.

jsdom is an implementation of a browser environment, which supports these types of UI tests.

Additional reading

jest testEnvironment documentation

Source https://stackoverflow.com/questions/69227566

QUESTION

Making a JSX syntax for a MockComponent and have it typed with typescript

Asked 2022-Mar-20 at 22:37

Wondering if anybody has some good suggestions on how to crack this. Got this test helper utils I have added some types to:

1import { jest } from '@jest/globals'
2import React from 'react'
3
4// https://learn.reactnativeschool.com/courses/781007/lectures/14173979
5export function mockComponent(moduleName: string, propOverrideFn = (props: Record<string, any>) => ({})) {
6  const RealComponent = jest.requireActual(moduleName) as React.ComponentType<any>
7  const CustomizedComponent = (props: Record<string, any>) => {
8    return React.createElement(
9      'CustomizedComponent',
10      {
11        ...props,
12        ...propOverrideFn(props),
13      },
14      props.children
15    )
16  }
17  CustomizedComponent.propTypes = RealComponent.propTypes
18
19  return CustomizedComponent
20}
21

So currently I can call it like this

1import { jest } from '@jest/globals'
2import React from 'react'
3
4// https://learn.reactnativeschool.com/courses/781007/lectures/14173979
5export function mockComponent(moduleName: string, propOverrideFn = (props: Record<string, any>) => ({})) {
6  const RealComponent = jest.requireActual(moduleName) as React.ComponentType<any>
7  const CustomizedComponent = (props: Record<string, any>) => {
8    return React.createElement(
9      'CustomizedComponent',
10      {
11        ...props,
12        ...propOverrideFn(props),
13      },
14      props.children
15    )
16  }
17  CustomizedComponent.propTypes = RealComponent.propTypes
18
19  return CustomizedComponent
20}
21jest.mock('react-native/Libraries/Components/Touchable/TouchableOpacity', () => {
22  return mockComponent('react-native/Libraries/Components/Touchable/TouchableOpacity', (props) => {
23    return {
24      onPress: props.disabled ? () => {} : props.onPress
25    }
26  })
27})
28

But I would like to be able to call it more like

1import { jest } from '@jest/globals'
2import React from 'react'
3
4// https://learn.reactnativeschool.com/courses/781007/lectures/14173979
5export function mockComponent(moduleName: string, propOverrideFn = (props: Record<string, any>) => ({})) {
6  const RealComponent = jest.requireActual(moduleName) as React.ComponentType<any>
7  const CustomizedComponent = (props: Record<string, any>) => {
8    return React.createElement(
9      'CustomizedComponent',
10      {
11        ...props,
12        ...propOverrideFn(props),
13      },
14      props.children
15    )
16  }
17  CustomizedComponent.propTypes = RealComponent.propTypes
18
19  return CustomizedComponent
20}
21jest.mock('react-native/Libraries/Components/Touchable/TouchableOpacity', () => {
22  return mockComponent('react-native/Libraries/Components/Touchable/TouchableOpacity', (props) => {
23    return {
24      onPress: props.disabled ? () => {} : props.onPress
25    }
26  })
27})
28
29jest.mock('react-native/Libraries/Components/Touchable/TouchableOpacity', () => {
30  return <MockComponent 
31          module='TouchableOpacity' 
32          onPress={props => props.disabled ? () => {} : props.onPress}
33         />
34})
35
36

or

1import { jest } from '@jest/globals'
2import React from 'react'
3
4// https://learn.reactnativeschool.com/courses/781007/lectures/14173979
5export function mockComponent(moduleName: string, propOverrideFn = (props: Record<string, any>) => ({})) {
6  const RealComponent = jest.requireActual(moduleName) as React.ComponentType<any>
7  const CustomizedComponent = (props: Record<string, any>) => {
8    return React.createElement(
9      'CustomizedComponent',
10      {
11        ...props,
12        ...propOverrideFn(props),
13      },
14      props.children
15    )
16  }
17  CustomizedComponent.propTypes = RealComponent.propTypes
18
19  return CustomizedComponent
20}
21jest.mock('react-native/Libraries/Components/Touchable/TouchableOpacity', () => {
22  return mockComponent('react-native/Libraries/Components/Touchable/TouchableOpacity', (props) => {
23    return {
24      onPress: props.disabled ? () => {} : props.onPress
25    }
26  })
27})
28
29jest.mock('react-native/Libraries/Components/Touchable/TouchableOpacity', () => {
30  return <MockComponent 
31          module='TouchableOpacity' 
32          onPress={props => props.disabled ? () => {} : props.onPress}
33         />
34})
35
36jest.mock('react-native/Libraries/Components/Touchable/TouchableOpacity', () => {
37 return <MockComponent 
38          module='TouchableOpacity'
39          propOverride={props => ({onPress: props.disabled ? () => {} : props.onPress, ...props})}
40        />
41})
42

ANSWER

Answered 2022-Mar-20 at 22:37

If you look at React without JSX, you'll see that the XML-inspired syntax (<MockComponent />) is just short for React.createElement('MockComponent').

Right now, if you renamed mockComponent to MockComponent and tried using the angle bracket syntax, the first issue is that your function receives two arguments. React components are either class components that take one constructor argument (props) or functional components that take one argument (again, props). The second issue is that your function returns a React functional component, when it needs to return a rendered React element.

One way to fix this issue is to convert mockComponent into a React functional component and make module and propOverride props of the FC.

1import { jest } from '@jest/globals'
2import React from 'react'
3
4// https://learn.reactnativeschool.com/courses/781007/lectures/14173979
5export function mockComponent(moduleName: string, propOverrideFn = (props: Record&lt;string, any&gt;) =&gt; ({})) {
6  const RealComponent = jest.requireActual(moduleName) as React.ComponentType&lt;any&gt;
7  const CustomizedComponent = (props: Record&lt;string, any&gt;) =&gt; {
8    return React.createElement(
9      'CustomizedComponent',
10      {
11        ...props,
12        ...propOverrideFn(props),
13      },
14      props.children
15    )
16  }
17  CustomizedComponent.propTypes = RealComponent.propTypes
18
19  return CustomizedComponent
20}
21jest.mock('react-native/Libraries/Components/Touchable/TouchableOpacity', () =&gt; {
22  return mockComponent('react-native/Libraries/Components/Touchable/TouchableOpacity', (props) =&gt; {
23    return {
24      onPress: props.disabled ? () =&gt; {} : props.onPress
25    }
26  })
27})
28
29jest.mock('react-native/Libraries/Components/Touchable/TouchableOpacity', () =&gt; {
30  return &lt;MockComponent 
31          module='TouchableOpacity' 
32          onPress={props =&gt; props.disabled ? () =&gt; {} : props.onPress}
33         /&gt;
34})
35
36jest.mock('react-native/Libraries/Components/Touchable/TouchableOpacity', () =&gt; {
37 return &lt;MockComponent 
38          module='TouchableOpacity'
39          propOverride={props =&gt; ({onPress: props.disabled ? () =&gt; {} : props.onPress, ...props})}
40        /&gt;
41})
42// https://learn.reactnativeschool.com/courses/781007/lectures/14173979
43export function MockComponent(props) {
44  const { moduleName, propOverrideFn, ...customComponentProps } = props;
45
46  const RealComponent = jest.requireActual(moduleName) as React.ComponentType&lt;any&gt;
47  const CustomizedComponent = (props: Record&lt;string, any&gt;) =&gt; {
48    return React.createElement(
49      'CustomizedComponent',
50      {
51        ...props,
52        ...propOverrideFn(props),
53      },
54      props.children
55    )
56  }
57  CustomizedComponent.propTypes = RealComponent.propTypes
58
59  return &lt;CustomizedComponent {...customComponentProps} /&gt;
60}
61

The differences are subtle but important. Here I modified MockComponent to take in a singular prop argument to be compatible with React.createElement(). This leads to the issue of how to differentiate props that are meant for the CustomizedComponent and what used to be arguments for mockComponent(). Here, I use the JavaScript destructuring and spread operators to separate module and propOverride from the props intended from CustomizedComponent.

Lastly, I use the JSX spread syntax to pass the arbitrary props intended for CustomizedComponent into CustomizedComponent, and I use angle brackets to render it (instead of returning a function).

I'll leave as an exercise for you to come up with the appropriate TypeScript definition for MockComponent's props. You can simply define it as the union of Record<string, any> and module and propOverride. However, you can get fancy and use a template definition so MockComponent<Toolbar> is a union of module and propOverride and Toolbar's props.

Oh, and I almost forgot. Your Jest call would look like

1import { jest } from '@jest/globals'
2import React from 'react'
3
4// https://learn.reactnativeschool.com/courses/781007/lectures/14173979
5export function mockComponent(moduleName: string, propOverrideFn = (props: Record&lt;string, any&gt;) =&gt; ({})) {
6  const RealComponent = jest.requireActual(moduleName) as React.ComponentType&lt;any&gt;
7  const CustomizedComponent = (props: Record&lt;string, any&gt;) =&gt; {
8    return React.createElement(
9      'CustomizedComponent',
10      {
11        ...props,
12        ...propOverrideFn(props),
13      },
14      props.children
15    )
16  }
17  CustomizedComponent.propTypes = RealComponent.propTypes
18
19  return CustomizedComponent
20}
21jest.mock('react-native/Libraries/Components/Touchable/TouchableOpacity', () =&gt; {
22  return mockComponent('react-native/Libraries/Components/Touchable/TouchableOpacity', (props) =&gt; {
23    return {
24      onPress: props.disabled ? () =&gt; {} : props.onPress
25    }
26  })
27})
28
29jest.mock('react-native/Libraries/Components/Touchable/TouchableOpacity', () =&gt; {
30  return &lt;MockComponent 
31          module='TouchableOpacity' 
32          onPress={props =&gt; props.disabled ? () =&gt; {} : props.onPress}
33         /&gt;
34})
35
36jest.mock('react-native/Libraries/Components/Touchable/TouchableOpacity', () =&gt; {
37 return &lt;MockComponent 
38          module='TouchableOpacity'
39          propOverride={props =&gt; ({onPress: props.disabled ? () =&gt; {} : props.onPress, ...props})}
40        /&gt;
41})
42// https://learn.reactnativeschool.com/courses/781007/lectures/14173979
43export function MockComponent(props) {
44  const { moduleName, propOverrideFn, ...customComponentProps } = props;
45
46  const RealComponent = jest.requireActual(moduleName) as React.ComponentType&lt;any&gt;
47  const CustomizedComponent = (props: Record&lt;string, any&gt;) =&gt; {
48    return React.createElement(
49      'CustomizedComponent',
50      {
51        ...props,
52        ...propOverrideFn(props),
53      },
54      props.children
55    )
56  }
57  CustomizedComponent.propTypes = RealComponent.propTypes
58
59  return &lt;CustomizedComponent {...customComponentProps} /&gt;
60}
61jest.mock('react-native/Libraries/Components/Touchable/TouchableOpacity', () =&gt; {
62    (props) =&gt; {
63        return &lt;MockComponent 
64            module='TouchableOpacity' 
65            onPress={props =&gt; props.disabled ? () =&gt; {} : props.onPress}
66            {...props}
67        /&gt;
68   }
69})
70

Source https://stackoverflow.com/questions/71478707

QUESTION

ESlint - Error: Must use import to load ES Module

Asked 2022-Mar-17 at 12:13

I am currently setting up a boilerplate with React, Typescript, styled components, webpack etc. and I am getting an error when trying to run eslint:

Error: Must use import to load ES Module

Here is a more verbose version of the error:

1/Users/ben/Desktop/development projects/react-boilerplate-styled-context/src/api/api.ts
2  0:0  error  Parsing error: Must use import to load ES Module: /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js
3require() of ES modules is not supported.
4require() of /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/babel-eslint/lib/require-from-eslint.js is an ES module file as it is a .js file whose nearest parent package.json contains &quot;type&quot;: &quot;module&quot; which defines all .js files in that package scope as ES modules.
5Instead rename definition.js to end in .cjs, change the requiring code to use import(), or remove &quot;type&quot;: &quot;module&quot; from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/package.json
6

The error occurs in every single one of my .js and .ts/ .tsx files where I only use import or the file doesn't even have an import at all. I understand what the error is saying but I have no idea why it is being thrown when in fact I only use imports or even no imports at all in some files.

Here is my package.json where I trigger the linter from using npm run lint:eslint:quiet:

1/Users/ben/Desktop/development projects/react-boilerplate-styled-context/src/api/api.ts
2  0:0  error  Parsing error: Must use import to load ES Module: /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js
3require() of ES modules is not supported.
4require() of /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/babel-eslint/lib/require-from-eslint.js is an ES module file as it is a .js file whose nearest parent package.json contains &quot;type&quot;: &quot;module&quot; which defines all .js files in that package scope as ES modules.
5Instead rename definition.js to end in .cjs, change the requiring code to use import(), or remove &quot;type&quot;: &quot;module&quot; from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/package.json
6{
7  &quot;name&quot;: &quot;my-react-boilerplate&quot;,
8  &quot;version&quot;: &quot;1.0.0&quot;,
9  &quot;description&quot;: &quot;&quot;,
10  &quot;main&quot;: &quot;index.tsx&quot;,
11  &quot;directories&quot;: {
12    &quot;test&quot;: &quot;test&quot;
13  },
14  &quot;engines&quot;: {
15    &quot;node&quot;: &quot;&gt;=14.0.0&quot;
16  },
17  &quot;type&quot;: &quot;module&quot;,
18  &quot;scripts&quot;: {
19    &quot;build&quot;: &quot;webpack --config webpack.prod.js&quot;,
20    &quot;dev&quot;: &quot;webpack serve --config webpack.dev.js&quot;,
21    &quot;lint&quot;: &quot;npm run typecheck &amp;&amp; npm run lint:css &amp;&amp; npm run lint:eslint:quiet&quot;,
22    &quot;lint:css&quot;: &quot;stylelint './src/**/*.{js,ts,tsx}'&quot;,
23    &quot;lint:eslint:quiet&quot;: &quot;eslint --ext .ts,.tsx,.js,.jsx  ./src --no-error-on-unmatched-pattern --quiet&quot;,
24    &quot;lint:eslint&quot;: &quot;eslint --ext .ts,.tsx,.js,.jsx  ./src --no-error-on-unmatched-pattern&quot;,
25    &quot;lint:eslint:fix&quot;: &quot;eslint --ext .ts,.tsx,.js,.jsx  ./src --no-error-on-unmatched-pattern --quiet --fix&quot;,
26    &quot;test&quot;: &quot;cross-env NODE_ENV=test jest --coverage&quot;,
27    &quot;test:watch&quot;: &quot;cross-env NODE_ENV=test jest --watchAll&quot;,
28    &quot;typecheck&quot;: &quot;tsc --noEmit&quot;,
29    &quot;precommit&quot;: &quot;npm run lint&quot;
30  },
31  &quot;lint-staged&quot;: {
32    &quot;*.{ts,tsx,js,jsx}&quot;: [
33      &quot;npm run lint:eslint:fix&quot;,
34      &quot;git add --force&quot;
35    ],
36    &quot;*.{md,json}&quot;: [
37      &quot;prettier --write&quot;,
38      &quot;git add --force&quot;
39    ]
40  },
41  &quot;husky&quot;: {
42    &quot;hooks&quot;: {
43      &quot;pre-commit&quot;: &quot;npx lint-staged &amp;&amp; npm run typecheck&quot;
44    }
45  },
46  &quot;resolutions&quot;: {
47    &quot;styled-components&quot;: &quot;^5&quot;
48  },
49  &quot;author&quot;: &quot;&quot;,
50  &quot;license&quot;: &quot;ISC&quot;,
51  &quot;devDependencies&quot;: {
52    &quot;@babel/core&quot;: &quot;^7.5.4&quot;,
53    &quot;@babel/plugin-proposal-class-properties&quot;: &quot;^7.5.0&quot;,
54    &quot;@babel/preset-env&quot;: &quot;^7.5.4&quot;,
55    &quot;@babel/preset-react&quot;: &quot;^7.0.0&quot;,
56    &quot;@types/history&quot;: &quot;^4.7.6&quot;,
57    &quot;@types/react&quot;: &quot;^17.0.29&quot;,
58    &quot;@types/react-dom&quot;: &quot;^17.0.9&quot;,
59    &quot;@types/react-router&quot;: &quot;^5.1.17&quot;,
60    &quot;@types/react-router-dom&quot;: &quot;^5.1.5&quot;,
61    &quot;@types/styled-components&quot;: &quot;^5.1.15&quot;,
62    &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^5.0.0&quot;,
63    &quot;babel-cli&quot;: &quot;^6.26.0&quot;,
64    &quot;babel-eslint&quot;: &quot;^10.0.2&quot;,
65    &quot;babel-loader&quot;: &quot;^8.0.0-beta.6&quot;,
66    &quot;babel-polyfill&quot;: &quot;^6.26.0&quot;,
67    &quot;babel-preset-env&quot;: &quot;^1.7.0&quot;,
68    &quot;babel-preset-react&quot;: &quot;^6.24.1&quot;,
69    &quot;babel-preset-stage-2&quot;: &quot;^6.24.1&quot;,
70    &quot;clean-webpack-plugin&quot;: &quot;^4.0.0&quot;,
71    &quot;dotenv-webpack&quot;: &quot;^7.0.3&quot;,
72    &quot;error-overlay-webpack-plugin&quot;: &quot;^1.0.0&quot;,
73    &quot;eslint&quot;: &quot;^8.0.0&quot;,
74    &quot;eslint-config-airbnb&quot;: &quot;^18.2.0&quot;,
75    &quot;eslint-config-prettier&quot;: &quot;^8.3.0&quot;,
76    &quot;eslint-config-with-prettier&quot;: &quot;^6.0.0&quot;,
77    &quot;eslint-plugin-compat&quot;: &quot;^3.3.0&quot;,
78    &quot;eslint-plugin-import&quot;: &quot;^2.25.2&quot;,
79    &quot;eslint-plugin-jsx-a11y&quot;: &quot;^6.2.3&quot;,
80    &quot;eslint-plugin-prettier&quot;: &quot;^4.0.0&quot;,
81    &quot;eslint-plugin-react&quot;: &quot;^7.14.2&quot;,
82    &quot;eslint-plugin-react-hooks&quot;: &quot;^4.2.0&quot;,
83    &quot;extract-text-webpack-plugin&quot;: &quot;^3.0.2&quot;,
84    &quot;file-loader&quot;: &quot;^6.2.0&quot;,
85    &quot;html-webpack-plugin&quot;: &quot;^5.3.2&quot;,
86    &quot;husky&quot;: &quot;^7.0.2&quot;,
87    &quot;prettier&quot;: &quot;^2.4.1&quot;,
88    &quot;raw-loader&quot;: &quot;^4.0.2&quot;,
89    &quot;style-loader&quot;: &quot;^3.3.0&quot;,
90    &quot;stylelint&quot;: &quot;^13.13.1&quot;,
91    &quot;stylelint-config-recommended&quot;: &quot;^5.0.0&quot;,
92    &quot;stylelint-config-styled-components&quot;: &quot;^0.1.1&quot;,
93    &quot;stylelint-processor-styled-components&quot;: &quot;^1.10.0&quot;,
94    &quot;ts-loader&quot;: &quot;^9.2.6&quot;,
95    &quot;tslint&quot;: &quot;^6.1.3&quot;,
96    &quot;typescript&quot;: &quot;^4.4.4&quot;,
97    &quot;url-loader&quot;: &quot;^4.1.1&quot;,
98    &quot;webpack&quot;: &quot;^5.58.2&quot;,
99    &quot;webpack-cli&quot;: &quot;^4.2.0&quot;,
100    &quot;webpack-dev-server&quot;: &quot;^4.3.1&quot;,
101    &quot;webpack-merge&quot;: &quot;^5.3.0&quot;
102  },
103  &quot;dependencies&quot;: {
104    &quot;history&quot;: &quot;^4.10.0&quot;,
105    &quot;process&quot;: &quot;^0.11.10&quot;,
106    &quot;react&quot;: &quot;^17.0.1&quot;,
107    &quot;react-dom&quot;: &quot;^17.0.1&quot;,
108    &quot;react-router-dom&quot;: &quot;^5.2.0&quot;,
109    &quot;styled-components&quot;: &quot;^5.2.1&quot;
110  }
111}
112

Here is my .eslintrc file:

1/Users/ben/Desktop/development projects/react-boilerplate-styled-context/src/api/api.ts
2  0:0  error  Parsing error: Must use import to load ES Module: /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js
3require() of ES modules is not supported.
4require() of /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/babel-eslint/lib/require-from-eslint.js is an ES module file as it is a .js file whose nearest parent package.json contains &quot;type&quot;: &quot;module&quot; which defines all .js files in that package scope as ES modules.
5Instead rename definition.js to end in .cjs, change the requiring code to use import(), or remove &quot;type&quot;: &quot;module&quot; from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/package.json
6{
7  &quot;name&quot;: &quot;my-react-boilerplate&quot;,
8  &quot;version&quot;: &quot;1.0.0&quot;,
9  &quot;description&quot;: &quot;&quot;,
10  &quot;main&quot;: &quot;index.tsx&quot;,
11  &quot;directories&quot;: {
12    &quot;test&quot;: &quot;test&quot;
13  },
14  &quot;engines&quot;: {
15    &quot;node&quot;: &quot;&gt;=14.0.0&quot;
16  },
17  &quot;type&quot;: &quot;module&quot;,
18  &quot;scripts&quot;: {
19    &quot;build&quot;: &quot;webpack --config webpack.prod.js&quot;,
20    &quot;dev&quot;: &quot;webpack serve --config webpack.dev.js&quot;,
21    &quot;lint&quot;: &quot;npm run typecheck &amp;&amp; npm run lint:css &amp;&amp; npm run lint:eslint:quiet&quot;,
22    &quot;lint:css&quot;: &quot;stylelint './src/**/*.{js,ts,tsx}'&quot;,
23    &quot;lint:eslint:quiet&quot;: &quot;eslint --ext .ts,.tsx,.js,.jsx  ./src --no-error-on-unmatched-pattern --quiet&quot;,
24    &quot;lint:eslint&quot;: &quot;eslint --ext .ts,.tsx,.js,.jsx  ./src --no-error-on-unmatched-pattern&quot;,
25    &quot;lint:eslint:fix&quot;: &quot;eslint --ext .ts,.tsx,.js,.jsx  ./src --no-error-on-unmatched-pattern --quiet --fix&quot;,
26    &quot;test&quot;: &quot;cross-env NODE_ENV=test jest --coverage&quot;,
27    &quot;test:watch&quot;: &quot;cross-env NODE_ENV=test jest --watchAll&quot;,
28    &quot;typecheck&quot;: &quot;tsc --noEmit&quot;,
29    &quot;precommit&quot;: &quot;npm run lint&quot;
30  },
31  &quot;lint-staged&quot;: {
32    &quot;*.{ts,tsx,js,jsx}&quot;: [
33      &quot;npm run lint:eslint:fix&quot;,
34      &quot;git add --force&quot;
35    ],
36    &quot;*.{md,json}&quot;: [
37      &quot;prettier --write&quot;,
38      &quot;git add --force&quot;
39    ]
40  },
41  &quot;husky&quot;: {
42    &quot;hooks&quot;: {
43      &quot;pre-commit&quot;: &quot;npx lint-staged &amp;&amp; npm run typecheck&quot;
44    }
45  },
46  &quot;resolutions&quot;: {
47    &quot;styled-components&quot;: &quot;^5&quot;
48  },
49  &quot;author&quot;: &quot;&quot;,
50  &quot;license&quot;: &quot;ISC&quot;,
51  &quot;devDependencies&quot;: {
52    &quot;@babel/core&quot;: &quot;^7.5.4&quot;,
53    &quot;@babel/plugin-proposal-class-properties&quot;: &quot;^7.5.0&quot;,
54    &quot;@babel/preset-env&quot;: &quot;^7.5.4&quot;,
55    &quot;@babel/preset-react&quot;: &quot;^7.0.0&quot;,
56    &quot;@types/history&quot;: &quot;^4.7.6&quot;,
57    &quot;@types/react&quot;: &quot;^17.0.29&quot;,
58    &quot;@types/react-dom&quot;: &quot;^17.0.9&quot;,
59    &quot;@types/react-router&quot;: &quot;^5.1.17&quot;,
60    &quot;@types/react-router-dom&quot;: &quot;^5.1.5&quot;,
61    &quot;@types/styled-components&quot;: &quot;^5.1.15&quot;,
62    &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^5.0.0&quot;,
63    &quot;babel-cli&quot;: &quot;^6.26.0&quot;,
64    &quot;babel-eslint&quot;: &quot;^10.0.2&quot;,
65    &quot;babel-loader&quot;: &quot;^8.0.0-beta.6&quot;,
66    &quot;babel-polyfill&quot;: &quot;^6.26.0&quot;,
67    &quot;babel-preset-env&quot;: &quot;^1.7.0&quot;,
68    &quot;babel-preset-react&quot;: &quot;^6.24.1&quot;,
69    &quot;babel-preset-stage-2&quot;: &quot;^6.24.1&quot;,
70    &quot;clean-webpack-plugin&quot;: &quot;^4.0.0&quot;,
71    &quot;dotenv-webpack&quot;: &quot;^7.0.3&quot;,
72    &quot;error-overlay-webpack-plugin&quot;: &quot;^1.0.0&quot;,
73    &quot;eslint&quot;: &quot;^8.0.0&quot;,
74    &quot;eslint-config-airbnb&quot;: &quot;^18.2.0&quot;,
75    &quot;eslint-config-prettier&quot;: &quot;^8.3.0&quot;,
76    &quot;eslint-config-with-prettier&quot;: &quot;^6.0.0&quot;,
77    &quot;eslint-plugin-compat&quot;: &quot;^3.3.0&quot;,
78    &quot;eslint-plugin-import&quot;: &quot;^2.25.2&quot;,
79    &quot;eslint-plugin-jsx-a11y&quot;: &quot;^6.2.3&quot;,
80    &quot;eslint-plugin-prettier&quot;: &quot;^4.0.0&quot;,
81    &quot;eslint-plugin-react&quot;: &quot;^7.14.2&quot;,
82    &quot;eslint-plugin-react-hooks&quot;: &quot;^4.2.0&quot;,
83    &quot;extract-text-webpack-plugin&quot;: &quot;^3.0.2&quot;,
84    &quot;file-loader&quot;: &quot;^6.2.0&quot;,
85    &quot;html-webpack-plugin&quot;: &quot;^5.3.2&quot;,
86    &quot;husky&quot;: &quot;^7.0.2&quot;,
87    &quot;prettier&quot;: &quot;^2.4.1&quot;,
88    &quot;raw-loader&quot;: &quot;^4.0.2&quot;,
89    &quot;style-loader&quot;: &quot;^3.3.0&quot;,
90    &quot;stylelint&quot;: &quot;^13.13.1&quot;,
91    &quot;stylelint-config-recommended&quot;: &quot;^5.0.0&quot;,
92    &quot;stylelint-config-styled-components&quot;: &quot;^0.1.1&quot;,
93    &quot;stylelint-processor-styled-components&quot;: &quot;^1.10.0&quot;,
94    &quot;ts-loader&quot;: &quot;^9.2.6&quot;,
95    &quot;tslint&quot;: &quot;^6.1.3&quot;,
96    &quot;typescript&quot;: &quot;^4.4.4&quot;,
97    &quot;url-loader&quot;: &quot;^4.1.1&quot;,
98    &quot;webpack&quot;: &quot;^5.58.2&quot;,
99    &quot;webpack-cli&quot;: &quot;^4.2.0&quot;,
100    &quot;webpack-dev-server&quot;: &quot;^4.3.1&quot;,
101    &quot;webpack-merge&quot;: &quot;^5.3.0&quot;
102  },
103  &quot;dependencies&quot;: {
104    &quot;history&quot;: &quot;^4.10.0&quot;,
105    &quot;process&quot;: &quot;^0.11.10&quot;,
106    &quot;react&quot;: &quot;^17.0.1&quot;,
107    &quot;react-dom&quot;: &quot;^17.0.1&quot;,
108    &quot;react-router-dom&quot;: &quot;^5.2.0&quot;,
109    &quot;styled-components&quot;: &quot;^5.2.1&quot;
110  }
111}
112{
113  &quot;extends&quot;: [&quot;airbnb&quot;, &quot;prettier&quot;],
114  &quot;parser&quot;: &quot;babel-eslint&quot;,
115  &quot;plugins&quot;: [&quot;prettier&quot;, &quot;@typescript-eslint&quot;],
116  &quot;parserOptions&quot;: {
117    &quot;ecmaVersion&quot;: 8,
118    &quot;ecmaFeatures&quot;: {
119      &quot;experimentalObjectRestSpread&quot;: true,
120      &quot;impliedStrict&quot;: true,
121      &quot;classes&quot;: true
122    }
123  },
124  &quot;env&quot;: {
125    &quot;browser&quot;: true,
126    &quot;node&quot;: true,
127    &quot;jest&quot;: true
128  },
129  &quot;rules&quot;: {
130    &quot;arrow-body-style&quot;: [&quot;error&quot;, &quot;as-needed&quot;],
131    &quot;class-methods-use-this&quot;: 0,
132    &quot;react/jsx-filename-extension&quot;: 0,
133    &quot;global-require&quot;: 0,
134    &quot;react/destructuring-assignment&quot;: 0,
135    &quot;import/named&quot;: 2,
136    &quot;linebreak-style&quot;: 0,
137    &quot;import/no-dynamic-require&quot;: 0,
138    &quot;import/no-named-as-default&quot;: 0,
139    &quot;import/no-unresolved&quot;: 2,
140    &quot;import/prefer-default-export&quot;: 0,
141    &quot;semi&quot;: [2, &quot;always&quot;],
142    &quot;max-len&quot;: [
143      &quot;error&quot;,
144      {
145        &quot;code&quot;: 80,
146        &quot;ignoreUrls&quot;: true,
147        &quot;ignoreComments&quot;: true,
148        &quot;ignoreStrings&quot;: true,
149        &quot;ignoreTemplateLiterals&quot;: true
150      }
151    ],
152    &quot;new-cap&quot;: [
153      2,
154      {
155        &quot;capIsNew&quot;: false,
156        &quot;newIsCap&quot;: true
157      }
158    ],
159    &quot;no-param-reassign&quot;: 0,
160    &quot;no-shadow&quot;: 0,
161    &quot;no-tabs&quot;: 2,
162    &quot;no-underscore-dangle&quot;: 0,
163    &quot;react/forbid-prop-types&quot;: [
164      &quot;error&quot;,
165      {
166        &quot;forbid&quot;: [&quot;any&quot;]
167      }
168    ],
169    &quot;import/no-extraneous-dependencies&quot;: [&quot;error&quot;, { &quot;devDependencies&quot;: true }],
170    &quot;react/jsx-no-bind&quot;: [
171      &quot;error&quot;,
172      {
173        &quot;ignoreRefs&quot;: true,
174        &quot;allowArrowFunctions&quot;: true,
175        &quot;allowBind&quot;: false
176      }
177    ],
178    &quot;react/no-unknown-property&quot;: [
179      2,
180      {
181        &quot;ignore&quot;: [&quot;itemscope&quot;, &quot;itemtype&quot;, &quot;itemprop&quot;]
182      }
183    ]
184  }
185}
186

And i'm not sure if relevant but also my tsconfig.eslint.json file:

1/Users/ben/Desktop/development projects/react-boilerplate-styled-context/src/api/api.ts
2  0:0  error  Parsing error: Must use import to load ES Module: /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js
3require() of ES modules is not supported.
4require() of /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/babel-eslint/lib/require-from-eslint.js is an ES module file as it is a .js file whose nearest parent package.json contains &quot;type&quot;: &quot;module&quot; which defines all .js files in that package scope as ES modules.
5Instead rename definition.js to end in .cjs, change the requiring code to use import(), or remove &quot;type&quot;: &quot;module&quot; from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/package.json
6{
7  &quot;name&quot;: &quot;my-react-boilerplate&quot;,
8  &quot;version&quot;: &quot;1.0.0&quot;,
9  &quot;description&quot;: &quot;&quot;,
10  &quot;main&quot;: &quot;index.tsx&quot;,
11  &quot;directories&quot;: {
12    &quot;test&quot;: &quot;test&quot;
13  },
14  &quot;engines&quot;: {
15    &quot;node&quot;: &quot;&gt;=14.0.0&quot;
16  },
17  &quot;type&quot;: &quot;module&quot;,
18  &quot;scripts&quot;: {
19    &quot;build&quot;: &quot;webpack --config webpack.prod.js&quot;,
20    &quot;dev&quot;: &quot;webpack serve --config webpack.dev.js&quot;,
21    &quot;lint&quot;: &quot;npm run typecheck &amp;&amp; npm run lint:css &amp;&amp; npm run lint:eslint:quiet&quot;,
22    &quot;lint:css&quot;: &quot;stylelint './src/**/*.{js,ts,tsx}'&quot;,
23    &quot;lint:eslint:quiet&quot;: &quot;eslint --ext .ts,.tsx,.js,.jsx  ./src --no-error-on-unmatched-pattern --quiet&quot;,
24    &quot;lint:eslint&quot;: &quot;eslint --ext .ts,.tsx,.js,.jsx  ./src --no-error-on-unmatched-pattern&quot;,
25    &quot;lint:eslint:fix&quot;: &quot;eslint --ext .ts,.tsx,.js,.jsx  ./src --no-error-on-unmatched-pattern --quiet --fix&quot;,
26    &quot;test&quot;: &quot;cross-env NODE_ENV=test jest --coverage&quot;,
27    &quot;test:watch&quot;: &quot;cross-env NODE_ENV=test jest --watchAll&quot;,
28    &quot;typecheck&quot;: &quot;tsc --noEmit&quot;,
29    &quot;precommit&quot;: &quot;npm run lint&quot;
30  },
31  &quot;lint-staged&quot;: {
32    &quot;*.{ts,tsx,js,jsx}&quot;: [
33      &quot;npm run lint:eslint:fix&quot;,
34      &quot;git add --force&quot;
35    ],
36    &quot;*.{md,json}&quot;: [
37      &quot;prettier --write&quot;,
38      &quot;git add --force&quot;
39    ]
40  },
41  &quot;husky&quot;: {
42    &quot;hooks&quot;: {
43      &quot;pre-commit&quot;: &quot;npx lint-staged &amp;&amp; npm run typecheck&quot;
44    }
45  },
46  &quot;resolutions&quot;: {
47    &quot;styled-components&quot;: &quot;^5&quot;
48  },
49  &quot;author&quot;: &quot;&quot;,
50  &quot;license&quot;: &quot;ISC&quot;,
51  &quot;devDependencies&quot;: {
52    &quot;@babel/core&quot;: &quot;^7.5.4&quot;,
53    &quot;@babel/plugin-proposal-class-properties&quot;: &quot;^7.5.0&quot;,
54    &quot;@babel/preset-env&quot;: &quot;^7.5.4&quot;,
55    &quot;@babel/preset-react&quot;: &quot;^7.0.0&quot;,
56    &quot;@types/history&quot;: &quot;^4.7.6&quot;,
57    &quot;@types/react&quot;: &quot;^17.0.29&quot;,
58    &quot;@types/react-dom&quot;: &quot;^17.0.9&quot;,
59    &quot;@types/react-router&quot;: &quot;^5.1.17&quot;,
60    &quot;@types/react-router-dom&quot;: &quot;^5.1.5&quot;,
61    &quot;@types/styled-components&quot;: &quot;^5.1.15&quot;,
62    &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^5.0.0&quot;,
63    &quot;babel-cli&quot;: &quot;^6.26.0&quot;,
64    &quot;babel-eslint&quot;: &quot;^10.0.2&quot;,
65    &quot;babel-loader&quot;: &quot;^8.0.0-beta.6&quot;,
66    &quot;babel-polyfill&quot;: &quot;^6.26.0&quot;,
67    &quot;babel-preset-env&quot;: &quot;^1.7.0&quot;,
68    &quot;babel-preset-react&quot;: &quot;^6.24.1&quot;,
69    &quot;babel-preset-stage-2&quot;: &quot;^6.24.1&quot;,
70    &quot;clean-webpack-plugin&quot;: &quot;^4.0.0&quot;,
71    &quot;dotenv-webpack&quot;: &quot;^7.0.3&quot;,
72    &quot;error-overlay-webpack-plugin&quot;: &quot;^1.0.0&quot;,
73    &quot;eslint&quot;: &quot;^8.0.0&quot;,
74    &quot;eslint-config-airbnb&quot;: &quot;^18.2.0&quot;,
75    &quot;eslint-config-prettier&quot;: &quot;^8.3.0&quot;,
76    &quot;eslint-config-with-prettier&quot;: &quot;^6.0.0&quot;,
77    &quot;eslint-plugin-compat&quot;: &quot;^3.3.0&quot;,
78    &quot;eslint-plugin-import&quot;: &quot;^2.25.2&quot;,
79    &quot;eslint-plugin-jsx-a11y&quot;: &quot;^6.2.3&quot;,
80    &quot;eslint-plugin-prettier&quot;: &quot;^4.0.0&quot;,
81    &quot;eslint-plugin-react&quot;: &quot;^7.14.2&quot;,
82    &quot;eslint-plugin-react-hooks&quot;: &quot;^4.2.0&quot;,
83    &quot;extract-text-webpack-plugin&quot;: &quot;^3.0.2&quot;,
84    &quot;file-loader&quot;: &quot;^6.2.0&quot;,
85    &quot;html-webpack-plugin&quot;: &quot;^5.3.2&quot;,
86    &quot;husky&quot;: &quot;^7.0.2&quot;,
87    &quot;prettier&quot;: &quot;^2.4.1&quot;,
88    &quot;raw-loader&quot;: &quot;^4.0.2&quot;,
89    &quot;style-loader&quot;: &quot;^3.3.0&quot;,
90    &quot;stylelint&quot;: &quot;^13.13.1&quot;,
91    &quot;stylelint-config-recommended&quot;: &quot;^5.0.0&quot;,
92    &quot;stylelint-config-styled-components&quot;: &quot;^0.1.1&quot;,
93    &quot;stylelint-processor-styled-components&quot;: &quot;^1.10.0&quot;,
94    &quot;ts-loader&quot;: &quot;^9.2.6&quot;,
95    &quot;tslint&quot;: &quot;^6.1.3&quot;,
96    &quot;typescript&quot;: &quot;^4.4.4&quot;,
97    &quot;url-loader&quot;: &quot;^4.1.1&quot;,
98    &quot;webpack&quot;: &quot;^5.58.2&quot;,
99    &quot;webpack-cli&quot;: &quot;^4.2.0&quot;,
100    &quot;webpack-dev-server&quot;: &quot;^4.3.1&quot;,
101    &quot;webpack-merge&quot;: &quot;^5.3.0&quot;
102  },
103  &quot;dependencies&quot;: {
104    &quot;history&quot;: &quot;^4.10.0&quot;,
105    &quot;process&quot;: &quot;^0.11.10&quot;,
106    &quot;react&quot;: &quot;^17.0.1&quot;,
107    &quot;react-dom&quot;: &quot;^17.0.1&quot;,
108    &quot;react-router-dom&quot;: &quot;^5.2.0&quot;,
109    &quot;styled-components&quot;: &quot;^5.2.1&quot;
110  }
111}
112{
113  &quot;extends&quot;: [&quot;airbnb&quot;, &quot;prettier&quot;],
114  &quot;parser&quot;: &quot;babel-eslint&quot;,
115  &quot;plugins&quot;: [&quot;prettier&quot;, &quot;@typescript-eslint&quot;],
116  &quot;parserOptions&quot;: {
117    &quot;ecmaVersion&quot;: 8,
118    &quot;ecmaFeatures&quot;: {
119      &quot;experimentalObjectRestSpread&quot;: true,
120      &quot;impliedStrict&quot;: true,
121      &quot;classes&quot;: true
122    }
123  },
124  &quot;env&quot;: {
125    &quot;browser&quot;: true,
126    &quot;node&quot;: true,
127    &quot;jest&quot;: true
128  },
129  &quot;rules&quot;: {
130    &quot;arrow-body-style&quot;: [&quot;error&quot;, &quot;as-needed&quot;],
131    &quot;class-methods-use-this&quot;: 0,
132    &quot;react/jsx-filename-extension&quot;: 0,
133    &quot;global-require&quot;: 0,
134    &quot;react/destructuring-assignment&quot;: 0,
135    &quot;import/named&quot;: 2,
136    &quot;linebreak-style&quot;: 0,
137    &quot;import/no-dynamic-require&quot;: 0,
138    &quot;import/no-named-as-default&quot;: 0,
139    &quot;import/no-unresolved&quot;: 2,
140    &quot;import/prefer-default-export&quot;: 0,
141    &quot;semi&quot;: [2, &quot;always&quot;],
142    &quot;max-len&quot;: [
143      &quot;error&quot;,
144      {
145        &quot;code&quot;: 80,
146        &quot;ignoreUrls&quot;: true,
147        &quot;ignoreComments&quot;: true,
148        &quot;ignoreStrings&quot;: true,
149        &quot;ignoreTemplateLiterals&quot;: true
150      }
151    ],
152    &quot;new-cap&quot;: [
153      2,
154      {
155        &quot;capIsNew&quot;: false,
156        &quot;newIsCap&quot;: true
157      }
158    ],
159    &quot;no-param-reassign&quot;: 0,
160    &quot;no-shadow&quot;: 0,
161    &quot;no-tabs&quot;: 2,
162    &quot;no-underscore-dangle&quot;: 0,
163    &quot;react/forbid-prop-types&quot;: [
164      &quot;error&quot;,
165      {
166        &quot;forbid&quot;: [&quot;any&quot;]
167      }
168    ],
169    &quot;import/no-extraneous-dependencies&quot;: [&quot;error&quot;, { &quot;devDependencies&quot;: true }],
170    &quot;react/jsx-no-bind&quot;: [
171      &quot;error&quot;,
172      {
173        &quot;ignoreRefs&quot;: true,
174        &quot;allowArrowFunctions&quot;: true,
175        &quot;allowBind&quot;: false
176      }
177    ],
178    &quot;react/no-unknown-property&quot;: [
179      2,
180      {
181        &quot;ignore&quot;: [&quot;itemscope&quot;, &quot;itemtype&quot;, &quot;itemprop&quot;]
182      }
183    ]
184  }
185}
186{
187  &quot;extends&quot;: &quot;./tsconfig.json&quot;,
188  &quot;include&quot;: [&quot;./src/**/*.ts&quot;, &quot;./src/**/*.tsx&quot;, &quot;./src/**/*.js&quot;],
189  &quot;exclude&quot;: [&quot;node_modules/**&quot;, &quot;build/**&quot;, &quot;coverage/**&quot;]
190}
191

Not sure if anyone has come across this before? Googling the error does not present any useful forums or raised bugs, most of them just state not to use require in your files which I am not.

ANSWER

Answered 2022-Mar-15 at 16:08

I think the problem is that you are trying to use the deprecated babel-eslint parser, last updated a year ago, which looks like it doesn't support ES6 modules. Updating to the latest parser seems to work, at least for simple linting.

So, do this:

  • In package.json, update the line "babel-eslint": "^10.0.2", to "@babel/eslint-parser": "^7.5.4",. This works with the code above but it may be better to use the latest version, which at the time of writing is 7.16.3.
  • Run npm i from a terminal/command prompt in the folder
  • In .eslintrc, update the parser line "parser": "babel-eslint", to "parser": "@babel/eslint-parser",
  • In .eslintrc, add "requireConfigFile": false, to the parserOptions section (underneath "ecmaVersion": 8,) (I needed this or babel was looking for config files I don't have)
  • Run the command to lint a file

Then, for me with just your two configuration files, the error goes away and I get appropriate linting errors.

Source https://stackoverflow.com/questions/69554485

QUESTION

Switch' is not exported from 'react-router-dom'

Asked 2022-Mar-01 at 09:07

In package.json file react-router-dom dependencies added. App component wrapped by BrowswerRouter , but when I wrap route by switch it says the following error Switch' is not exported from 'react-router-dom'. I deleted the package.json.lock ,node modules, installed npm again and npm install @babel/core --save. Still not working. I successfully wasted 6 hour for this. Can you please help me to fix this? why it's not importing?

Index.js

1import {BrowserRouter} from 'react-router-dom';
2
3ReactDOM.render(
4  &lt;BrowserRouter&gt;
5     &lt;App /&gt;
6  &lt;/BrowserRouter&gt;,
7  document.getElementById('root')
8);
9

App.js:

1import {BrowserRouter} from 'react-router-dom';
2
3ReactDOM.render(
4  &lt;BrowserRouter&gt;
5     &lt;App /&gt;
6  &lt;/BrowserRouter&gt;,
7  document.getElementById('root')
8);
9 import logo from './logo.svg';
10import './App.css';
11import React from 'react';
12import {Switch,Route,Link} from 'react-router-dom';
13import Home from './Home';
14class App extends React.Component {
15  componentDidMount(){
16    alert('mounting');
17  }
18  componentDidUpdate(){
19    alert('updated');
20  }
21 render(){
22  return (
23    
24    &lt;div className=&quot;App&quot;&gt;
25     
26    &lt;div&gt;
27      &lt;Link to=&quot;/&quot;&gt;Home&lt;/Link&gt;
28    &lt;/div&gt;
29
30    &lt;hr /&gt;
31
32    &lt;Switch&gt;
33      &lt;Route exact path=&quot;/&quot;&gt;
34        &lt;Home/&gt;
35      &lt;/Route&gt;
36    &lt;/Switch&gt;
37 
38  &lt;/div&gt;
39 
40);
41 }
42}
43
44export default App;
45
46import React from 'react';
47
48    const Home = () =&gt; {
49    return &lt;h1&gt;Home&lt;/h1&gt;;
50  };
51  
52  export default Home;
53

package.json

1import {BrowserRouter} from 'react-router-dom';
2
3ReactDOM.render(
4  &lt;BrowserRouter&gt;
5     &lt;App /&gt;
6  &lt;/BrowserRouter&gt;,
7  document.getElementById('root')
8);
9 import logo from './logo.svg';
10import './App.css';
11import React from 'react';
12import {Switch,Route,Link} from 'react-router-dom';
13import Home from './Home';
14class App extends React.Component {
15  componentDidMount(){
16    alert('mounting');
17  }
18  componentDidUpdate(){
19    alert('updated');
20  }
21 render(){
22  return (
23    
24    &lt;div className=&quot;App&quot;&gt;
25     
26    &lt;div&gt;
27      &lt;Link to=&quot;/&quot;&gt;Home&lt;/Link&gt;
28    &lt;/div&gt;
29
30    &lt;hr /&gt;
31
32    &lt;Switch&gt;
33      &lt;Route exact path=&quot;/&quot;&gt;
34        &lt;Home/&gt;
35      &lt;/Route&gt;
36    &lt;/Switch&gt;
37 
38  &lt;/div&gt;
39 
40);
41 }
42}
43
44export default App;
45
46import React from 'react';
47
48    const Home = () =&gt; {
49    return &lt;h1&gt;Home&lt;/h1&gt;;
50  };
51  
52  export default Home;
53&quot;dependencies&quot;: {
54    &quot;@babel/core&quot;: &quot;^7.16.0&quot;,
55    &quot;@testing-library/jest-dom&quot;: &quot;^5.11.4&quot;,
56    &quot;@testing-library/react&quot;: &quot;^11.1.0&quot;,
57    &quot;@testing-library/user-event&quot;: &quot;^12.1.10&quot;,
58    &quot;react&quot;: &quot;^17.0.2&quot;,
59    &quot;react-dom&quot;: &quot;^17.0.2&quot;,
60    &quot;react-router&quot;: &quot;^6.0.0&quot;,
61    &quot;react-router-dom&quot;: &quot;^6.0.0&quot;,
62    &quot;react-scripts&quot;: &quot;4.0.3&quot;,
63    &quot;web-vitals&quot;: &quot;^1.0.1&quot;
64  },
65

ANSWER

Answered 2021-Nov-04 at 18:10
Using Routes instead of Switch in react-router v6

You are using react-router-dom version 6, which replaced Switch with the Routes component

1import {BrowserRouter} from 'react-router-dom';
2
3ReactDOM.render(
4  &lt;BrowserRouter&gt;
5     &lt;App /&gt;
6  &lt;/BrowserRouter&gt;,
7  document.getElementById('root')
8);
9 import logo from './logo.svg';
10import './App.css';
11import React from 'react';
12import {Switch,Route,Link} from 'react-router-dom';
13import Home from './Home';
14class App extends React.Component {
15  componentDidMount(){
16    alert('mounting');
17  }
18  componentDidUpdate(){
19    alert('updated');
20  }
21 render(){
22  return (
23    
24    &lt;div className=&quot;App&quot;&gt;
25     
26    &lt;div&gt;
27      &lt;Link to=&quot;/&quot;&gt;Home&lt;/Link&gt;
28    &lt;/div&gt;
29
30    &lt;hr /&gt;
31
32    &lt;Switch&gt;
33      &lt;Route exact path=&quot;/&quot;&gt;
34        &lt;Home/&gt;
35      &lt;/Route&gt;
36    &lt;/Switch&gt;
37 
38  &lt;/div&gt;
39 
40);
41 }
42}
43
44export default App;
45
46import React from 'react';
47
48    const Home = () =&gt; {
49    return &lt;h1&gt;Home&lt;/h1&gt;;
50  };
51  
52  export default Home;
53&quot;dependencies&quot;: {
54    &quot;@babel/core&quot;: &quot;^7.16.0&quot;,
55    &quot;@testing-library/jest-dom&quot;: &quot;^5.11.4&quot;,
56    &quot;@testing-library/react&quot;: &quot;^11.1.0&quot;,
57    &quot;@testing-library/user-event&quot;: &quot;^12.1.10&quot;,
58    &quot;react&quot;: &quot;^17.0.2&quot;,
59    &quot;react-dom&quot;: &quot;^17.0.2&quot;,
60    &quot;react-router&quot;: &quot;^6.0.0&quot;,
61    &quot;react-router-dom&quot;: &quot;^6.0.0&quot;,
62    &quot;react-scripts&quot;: &quot;4.0.3&quot;,
63    &quot;web-vitals&quot;: &quot;^1.0.1&quot;
64  },
65import {
66  BrowserRouter,
67  Routes, // instead of &quot;Switch&quot;
68  Route,
69} from &quot;react-router-dom&quot;;
70
71// ...
72
73    &lt;BrowserRouter&gt;
74      &lt;Routes&gt;
75        &lt;Route exact path=&quot;/&quot; element={&lt;Home /&gt;}&gt;
76          &lt;Home/&gt;
77        &lt;/Route&gt;
78      &lt;/Routes&gt;
79    &lt;/BrowserRouter&gt;
80

Note that you now also pass your component as the element prop instead of using children.

Source https://stackoverflow.com/questions/69843615

QUESTION

&quot;Cannot read properties of undefined (reading 'pathname')&quot; when testing pages in the v6 React Router

Asked 2022-Feb-03 at 00:48

When testing components with <Link>s, for example in my answer to Recommended approach for route-based tests within routes of react-router, I often use the following pattern to get access to the current location for testing purposes:

1const renderInRouter = () =&gt; {
2  const history = createMemoryHistory();
3  const wrapper = render(
4    &lt;Router history={history}&gt;
5      &lt;MyPage /&gt;
6    &lt;/Router&gt;
7  );
8  return { ...wrapper, history };
9}
10

This worked fine up to v5.3, but after upgrading to v6 I get:

1const renderInRouter = () =&gt; {
2  const history = createMemoryHistory();
3  const wrapper = render(
4    &lt;Router history={history}&gt;
5      &lt;MyPage /&gt;
6    &lt;/Router&gt;
7  );
8  return { ...wrapper, history };
9}
10 FAIL  ./demo.test.js
11  βœ• works (205 ms)
12
13  ● works
14
15    TypeError: Cannot read properties of undefined (reading 'pathname')
16
17      at Router (../packages/react-router/index.tsx:281:5)
18
19      ...
20

This use-case isn't covered in the migration docs, v6 has no testing guides so far and, although the API reference does show that the history prop is no longer expected:

1const renderInRouter = () =&gt; {
2  const history = createMemoryHistory();
3  const wrapper = render(
4    &lt;Router history={history}&gt;
5      &lt;MyPage /&gt;
6    &lt;/Router&gt;
7  );
8  return { ...wrapper, history };
9}
10 FAIL  ./demo.test.js
11  βœ• works (205 ms)
12
13  ● works
14
15    TypeError: Cannot read properties of undefined (reading 'pathname')
16
17      at Router (../packages/react-router/index.tsx:281:5)
18
19      ...
20interface RouterProps {
21  basename?: string;
22  children?: React.ReactNode;
23  location: Partial&lt;Location&gt; | string;
24  navigationType?: NavigationType;
25  navigator: Navigator;
26  static?: boolean;
27}
28

it's not clear what the v6 equivalent is; I tried switching to navigator={history} but still got the same error.

To reproduce, copy the following files into a new directory and run npm install then npm test:

package.json

1const renderInRouter = () =&gt; {
2  const history = createMemoryHistory();
3  const wrapper = render(
4    &lt;Router history={history}&gt;
5      &lt;MyPage /&gt;
6    &lt;/Router&gt;
7  );
8  return { ...wrapper, history };
9}
10 FAIL  ./demo.test.js
11  βœ• works (205 ms)
12
13  ● works
14
15    TypeError: Cannot read properties of undefined (reading 'pathname')
16
17      at Router (../packages/react-router/index.tsx:281:5)
18
19      ...
20interface RouterProps {
21  basename?: string;
22  children?: React.ReactNode;
23  location: Partial&lt;Location&gt; | string;
24  navigationType?: NavigationType;
25  navigator: Navigator;
26  static?: boolean;
27}
28{
29  &quot;name&quot;: &quot;router6-demo&quot;,
30  &quot;version&quot;: &quot;1.0.0&quot;,
31  &quot;description&quot;: &quot;&quot;,
32  &quot;main&quot;: &quot;index.js&quot;,
33  &quot;scripts&quot;: {
34    &quot;test&quot;: &quot;jest&quot;
35  },
36  &quot;jest&quot;: {
37    &quot;testEnvironment&quot;: &quot;jsdom&quot;
38  },
39  &quot;babel&quot;: {
40    &quot;presets&quot;: [
41      &quot;@babel/preset-react&quot;
42    ]
43  },
44  &quot;keywords&quot;: [],
45  &quot;author&quot;: &quot;&quot;,
46  &quot;license&quot;: &quot;ISC&quot;,
47  &quot;devDependencies&quot;: {
48    &quot;@babel/preset-react&quot;: &quot;^7.16.0&quot;,
49    &quot;@testing-library/react&quot;: &quot;^12.1.2&quot;,
50    &quot;jest&quot;: &quot;^27.3.1&quot;,
51    &quot;react&quot;: &quot;^17.0.2&quot;,
52    &quot;react-dom&quot;: &quot;^17.0.2&quot;,
53    &quot;react-router-dom&quot;: &quot;^6.0.0&quot;
54  }
55}
56
57

index.test.js:

1const renderInRouter = () =&gt; {
2  const history = createMemoryHistory();
3  const wrapper = render(
4    &lt;Router history={history}&gt;
5      &lt;MyPage /&gt;
6    &lt;/Router&gt;
7  );
8  return { ...wrapper, history };
9}
10 FAIL  ./demo.test.js
11  βœ• works (205 ms)
12
13  ● works
14
15    TypeError: Cannot read properties of undefined (reading 'pathname')
16
17      at Router (../packages/react-router/index.tsx:281:5)
18
19      ...
20interface RouterProps {
21  basename?: string;
22  children?: React.ReactNode;
23  location: Partial&lt;Location&gt; | string;
24  navigationType?: NavigationType;
25  navigator: Navigator;
26  static?: boolean;
27}
28{
29  &quot;name&quot;: &quot;router6-demo&quot;,
30  &quot;version&quot;: &quot;1.0.0&quot;,
31  &quot;description&quot;: &quot;&quot;,
32  &quot;main&quot;: &quot;index.js&quot;,
33  &quot;scripts&quot;: {
34    &quot;test&quot;: &quot;jest&quot;
35  },
36  &quot;jest&quot;: {
37    &quot;testEnvironment&quot;: &quot;jsdom&quot;
38  },
39  &quot;babel&quot;: {
40    &quot;presets&quot;: [
41      &quot;@babel/preset-react&quot;
42    ]
43  },
44  &quot;keywords&quot;: [],
45  &quot;author&quot;: &quot;&quot;,
46  &quot;license&quot;: &quot;ISC&quot;,
47  &quot;devDependencies&quot;: {
48    &quot;@babel/preset-react&quot;: &quot;^7.16.0&quot;,
49    &quot;@testing-library/react&quot;: &quot;^12.1.2&quot;,
50    &quot;jest&quot;: &quot;^27.3.1&quot;,
51    &quot;react&quot;: &quot;^17.0.2&quot;,
52    &quot;react-dom&quot;: &quot;^17.0.2&quot;,
53    &quot;react-router-dom&quot;: &quot;^6.0.0&quot;
54  }
55}
56
57const { render } = require(&quot;@testing-library/react&quot;);
58const { createMemoryHistory } = require(&quot;history&quot;);
59const React = require(&quot;react&quot;);
60const { Router } = require(&quot;react-router-dom&quot;);
61
62it(&quot;used to work&quot;, () =&gt; {
63  render(
64    &lt;Router history={createMemoryHistory()}&gt;&lt;/Router&gt;
65  );
66});
67

If you npm install --save-dev react-router@5 and run npm test again, you can see that this passes in v5.

ANSWER

Answered 2021-Nov-06 at 10:28

React Router v6 splits apart the history into multiple pieces, for this use case the relevant parts are the navigator and the location. This change is hinted at in Use useNavigate instead of useHistory, and you can see it in the definition of the Navigator type used in the Router props:

1const renderInRouter = () =&gt; {
2  const history = createMemoryHistory();
3  const wrapper = render(
4    &lt;Router history={history}&gt;
5      &lt;MyPage /&gt;
6    &lt;/Router&gt;
7  );
8  return { ...wrapper, history };
9}
10 FAIL  ./demo.test.js
11  βœ• works (205 ms)
12
13  ● works
14
15    TypeError: Cannot read properties of undefined (reading 'pathname')
16
17      at Router (../packages/react-router/index.tsx:281:5)
18
19      ...
20interface RouterProps {
21  basename?: string;
22  children?: React.ReactNode;
23  location: Partial&lt;Location&gt; | string;
24  navigationType?: NavigationType;
25  navigator: Navigator;
26  static?: boolean;
27}
28{
29  &quot;name&quot;: &quot;router6-demo&quot;,
30  &quot;version&quot;: &quot;1.0.0&quot;,
31  &quot;description&quot;: &quot;&quot;,
32  &quot;main&quot;: &quot;index.js&quot;,
33  &quot;scripts&quot;: {
34    &quot;test&quot;: &quot;jest&quot;
35  },
36  &quot;jest&quot;: {
37    &quot;testEnvironment&quot;: &quot;jsdom&quot;
38  },
39  &quot;babel&quot;: {
40    &quot;presets&quot;: [
41      &quot;@babel/preset-react&quot;
42    ]
43  },
44  &quot;keywords&quot;: [],
45  &quot;author&quot;: &quot;&quot;,
46  &quot;license&quot;: &quot;ISC&quot;,
47  &quot;devDependencies&quot;: {
48    &quot;@babel/preset-react&quot;: &quot;^7.16.0&quot;,
49    &quot;@testing-library/react&quot;: &quot;^12.1.2&quot;,
50    &quot;jest&quot;: &quot;^27.3.1&quot;,
51    &quot;react&quot;: &quot;^17.0.2&quot;,
52    &quot;react-dom&quot;: &quot;^17.0.2&quot;,
53    &quot;react-router-dom&quot;: &quot;^6.0.0&quot;
54  }
55}
56
57const { render } = require(&quot;@testing-library/react&quot;);
58const { createMemoryHistory } = require(&quot;history&quot;);
59const React = require(&quot;react&quot;);
60const { Router } = require(&quot;react-router-dom&quot;);
61
62it(&quot;used to work&quot;, () =&gt; {
63  render(
64    &lt;Router history={createMemoryHistory()}&gt;&lt;/Router&gt;
65  );
66});
67export declare type Navigator = Omit&lt;History, &quot;action&quot; | &quot;location&quot; | &quot;back&quot; | &quot;forward&quot; | &quot;listen&quot; | &quot;block&quot;&gt;;
68

Just changing history={history} to navigator={history} still left the location prop, from which the router was trying to access the pathname (among other properties), undefined. To get the test working again, update the rendering as follows:

1const renderInRouter = () =&gt; {
2  const history = createMemoryHistory();
3  const wrapper = render(
4    &lt;Router history={history}&gt;
5      &lt;MyPage /&gt;
6    &lt;/Router&gt;
7  );
8  return { ...wrapper, history };
9}
10 FAIL  ./demo.test.js
11  βœ• works (205 ms)
12
13  ● works
14
15    TypeError: Cannot read properties of undefined (reading 'pathname')
16
17      at Router (../packages/react-router/index.tsx:281:5)
18
19      ...
20interface RouterProps {
21  basename?: string;
22  children?: React.ReactNode;
23  location: Partial&lt;Location&gt; | string;
24  navigationType?: NavigationType;
25  navigator: Navigator;
26  static?: boolean;
27}
28{
29  &quot;name&quot;: &quot;router6-demo&quot;,
30  &quot;version&quot;: &quot;1.0.0&quot;,
31  &quot;description&quot;: &quot;&quot;,
32  &quot;main&quot;: &quot;index.js&quot;,
33  &quot;scripts&quot;: {
34    &quot;test&quot;: &quot;jest&quot;
35  },
36  &quot;jest&quot;: {
37    &quot;testEnvironment&quot;: &quot;jsdom&quot;
38  },
39  &quot;babel&quot;: {
40    &quot;presets&quot;: [
41      &quot;@babel/preset-react&quot;
42    ]
43  },
44  &quot;keywords&quot;: [],
45  &quot;author&quot;: &quot;&quot;,
46  &quot;license&quot;: &quot;ISC&quot;,
47  &quot;devDependencies&quot;: {
48    &quot;@babel/preset-react&quot;: &quot;^7.16.0&quot;,
49    &quot;@testing-library/react&quot;: &quot;^12.1.2&quot;,
50    &quot;jest&quot;: &quot;^27.3.1&quot;,
51    &quot;react&quot;: &quot;^17.0.2&quot;,
52    &quot;react-dom&quot;: &quot;^17.0.2&quot;,
53    &quot;react-router-dom&quot;: &quot;^6.0.0&quot;
54  }
55}
56
57const { render } = require(&quot;@testing-library/react&quot;);
58const { createMemoryHistory } = require(&quot;history&quot;);
59const React = require(&quot;react&quot;);
60const { Router } = require(&quot;react-router-dom&quot;);
61
62it(&quot;used to work&quot;, () =&gt; {
63  render(
64    &lt;Router history={createMemoryHistory()}&gt;&lt;/Router&gt;
65  );
66});
67export declare type Navigator = Omit&lt;History, &quot;action&quot; | &quot;location&quot; | &quot;back&quot; | &quot;forward&quot; | &quot;listen&quot; | &quot;block&quot;&gt;;
68const { render } = require(&quot;@testing-library/react&quot;);
69const { createMemoryHistory } = require(&quot;history&quot;);
70const React = require(&quot;react&quot;);
71const { Router } = require(&quot;react-router-dom&quot;);
72
73it(&quot;works&quot;, () =&gt; {
74  const history = createMemoryHistory();
75  render(
76    &lt;Router location={history.location} navigator={history}&gt;&lt;/Router&gt;
77  );
78});
79

Source https://stackoverflow.com/questions/69859509

QUESTION

eslint / typescript: Unable to resolve path to module

Asked 2022-Feb-02 at 23:32

My .eslintrc.json is:

1{
2    &quot;env&quot;: {
3        &quot;browser&quot;: true,
4        &quot;commonjs&quot;: true,
5        &quot;es6&quot;: true,
6        &quot;node&quot;: true,
7        &quot;jest&quot;: true
8    },
9    &quot;parserOptions&quot;: {
10        &quot;ecmaFeatures&quot;: {
11            &quot;jsx&quot;: true
12        },
13        &quot;sourceType&quot;: &quot;module&quot;
14    },
15    &quot;plugins&quot;: [
16        &quot;react&quot;,
17        &quot;prettier&quot;,
18        &quot;import&quot;
19    ],
20    &quot;extends&quot;: [
21        &quot;airbnb&quot;,
22        &quot;airbnb/hooks&quot;,
23        &quot;plugin:@typescript-eslint/recommended&quot;,
24        &quot;plugin:react/recommended&quot;,
25        &quot;plugin:import/errors&quot;,
26        &quot;plugin:import/warnings&quot;,
27        &quot;plugin:import/typescript&quot;,
28        &quot;prettier&quot;
29    ],
30    &quot;root&quot;: true,
31    &quot;rules&quot;: {
32        &quot;no-const-assign&quot;: 1,
33        &quot;no-extra-semi&quot;: 0,
34        &quot;semi&quot;: 0,
35        &quot;no-fallthrough&quot;: 0,
36        &quot;no-empty&quot;: 0,
37        &quot;no-mixed-spaces-and-tabs&quot;: 0,
38        &quot;no-redeclare&quot;: 0,
39        &quot;no-this-before-super&quot;: 1,
40        &quot;no-unreachable&quot;: 1,
41        &quot;no-use-before-define&quot;: 0,
42        &quot;constructor-super&quot;: 1,
43        &quot;curly&quot;: 0,
44        &quot;eqeqeq&quot;: 0,
45        &quot;func-names&quot;: 0,
46        &quot;valid-typeof&quot;: 1,
47        &quot;import/extensions&quot;: 0,
48        &quot;react/jsx-filename-extension&quot;: 0,
49        // note you must disable the base rule as it can report incorrect errors
50        &quot;no-shadow&quot;: 0,
51        &quot;@typescript-eslint/no-shadow&quot;: [
52            1
53        ],
54        &quot;no-unused-vars&quot;: 0,
55        &quot;@typescript-eslint/no-unused-vars&quot;: 1,
56        &quot;no-undef&quot;: 0,
57        &quot;jsx-a11y/click-events-have-key-events&quot;: 0,
58        &quot;jsx-a11y/no-static-element-interactions&quot;: 0,
59        &quot;@typescript-eslint/explicit-module-boundary-types&quot;: 0,
60        &quot;react/button-has-type&quot;: 0,
61        &quot;react/require-default-props&quot;: 0,
62        &quot;react/prop-types&quot;: 0,
63        &quot;react-hooks/exhaustive-deps&quot;: 0,
64        &quot;react/jsx-props-no-spreading&quot;: 0
65    },
66    &quot;settings&quot;: {
67        &quot;import/resolver&quot;: {
68            &quot;node&quot;: {
69                &quot;extensions&quot;: [
70                    &quot;.js&quot;,
71                    &quot;.jsx&quot;,
72                    &quot;.ts&quot;,
73                    &quot;.tsx&quot;
74                ]
75            }
76        }
77    }
78}
79

In a file src/components/elements/ProtectedRoutes/InviteRoute.tsx, I have:

1{
2    &quot;env&quot;: {
3        &quot;browser&quot;: true,
4        &quot;commonjs&quot;: true,
5        &quot;es6&quot;: true,
6        &quot;node&quot;: true,
7        &quot;jest&quot;: true
8    },
9    &quot;parserOptions&quot;: {
10        &quot;ecmaFeatures&quot;: {
11            &quot;jsx&quot;: true
12        },
13        &quot;sourceType&quot;: &quot;module&quot;
14    },
15    &quot;plugins&quot;: [
16        &quot;react&quot;,
17        &quot;prettier&quot;,
18        &quot;import&quot;
19    ],
20    &quot;extends&quot;: [
21        &quot;airbnb&quot;,
22        &quot;airbnb/hooks&quot;,
23        &quot;plugin:@typescript-eslint/recommended&quot;,
24        &quot;plugin:react/recommended&quot;,
25        &quot;plugin:import/errors&quot;,
26        &quot;plugin:import/warnings&quot;,
27        &quot;plugin:import/typescript&quot;,
28        &quot;prettier&quot;
29    ],
30    &quot;root&quot;: true,
31    &quot;rules&quot;: {
32        &quot;no-const-assign&quot;: 1,
33        &quot;no-extra-semi&quot;: 0,
34        &quot;semi&quot;: 0,
35        &quot;no-fallthrough&quot;: 0,
36        &quot;no-empty&quot;: 0,
37        &quot;no-mixed-spaces-and-tabs&quot;: 0,
38        &quot;no-redeclare&quot;: 0,
39        &quot;no-this-before-super&quot;: 1,
40        &quot;no-unreachable&quot;: 1,
41        &quot;no-use-before-define&quot;: 0,
42        &quot;constructor-super&quot;: 1,
43        &quot;curly&quot;: 0,
44        &quot;eqeqeq&quot;: 0,
45        &quot;func-names&quot;: 0,
46        &quot;valid-typeof&quot;: 1,
47        &quot;import/extensions&quot;: 0,
48        &quot;react/jsx-filename-extension&quot;: 0,
49        // note you must disable the base rule as it can report incorrect errors
50        &quot;no-shadow&quot;: 0,
51        &quot;@typescript-eslint/no-shadow&quot;: [
52            1
53        ],
54        &quot;no-unused-vars&quot;: 0,
55        &quot;@typescript-eslint/no-unused-vars&quot;: 1,
56        &quot;no-undef&quot;: 0,
57        &quot;jsx-a11y/click-events-have-key-events&quot;: 0,
58        &quot;jsx-a11y/no-static-element-interactions&quot;: 0,
59        &quot;@typescript-eslint/explicit-module-boundary-types&quot;: 0,
60        &quot;react/button-has-type&quot;: 0,
61        &quot;react/require-default-props&quot;: 0,
62        &quot;react/prop-types&quot;: 0,
63        &quot;react-hooks/exhaustive-deps&quot;: 0,
64        &quot;react/jsx-props-no-spreading&quot;: 0
65    },
66    &quot;settings&quot;: {
67        &quot;import/resolver&quot;: {
68            &quot;node&quot;: {
69                &quot;extensions&quot;: [
70                    &quot;.js&quot;,
71                    &quot;.jsx&quot;,
72                    &quot;.ts&quot;,
73                    &quot;.tsx&quot;
74                ]
75            }
76        }
77    }
78}
79import routeNames from 'constants/routeNames';
80import useRoles from 'hooks/roles';
81import { ROLE } from 'shared/src/types/enums';
82

The app runs fine, but when I run lint, I get errors:

1{
2    &quot;env&quot;: {
3        &quot;browser&quot;: true,
4        &quot;commonjs&quot;: true,
5        &quot;es6&quot;: true,
6        &quot;node&quot;: true,
7        &quot;jest&quot;: true
8    },
9    &quot;parserOptions&quot;: {
10        &quot;ecmaFeatures&quot;: {
11            &quot;jsx&quot;: true
12        },
13        &quot;sourceType&quot;: &quot;module&quot;
14    },
15    &quot;plugins&quot;: [
16        &quot;react&quot;,
17        &quot;prettier&quot;,
18        &quot;import&quot;
19    ],
20    &quot;extends&quot;: [
21        &quot;airbnb&quot;,
22        &quot;airbnb/hooks&quot;,
23        &quot;plugin:@typescript-eslint/recommended&quot;,
24        &quot;plugin:react/recommended&quot;,
25        &quot;plugin:import/errors&quot;,
26        &quot;plugin:import/warnings&quot;,
27        &quot;plugin:import/typescript&quot;,
28        &quot;prettier&quot;
29    ],
30    &quot;root&quot;: true,
31    &quot;rules&quot;: {
32        &quot;no-const-assign&quot;: 1,
33        &quot;no-extra-semi&quot;: 0,
34        &quot;semi&quot;: 0,
35        &quot;no-fallthrough&quot;: 0,
36        &quot;no-empty&quot;: 0,
37        &quot;no-mixed-spaces-and-tabs&quot;: 0,
38        &quot;no-redeclare&quot;: 0,
39        &quot;no-this-before-super&quot;: 1,
40        &quot;no-unreachable&quot;: 1,
41        &quot;no-use-before-define&quot;: 0,
42        &quot;constructor-super&quot;: 1,
43        &quot;curly&quot;: 0,
44        &quot;eqeqeq&quot;: 0,
45        &quot;func-names&quot;: 0,
46        &quot;valid-typeof&quot;: 1,
47        &quot;import/extensions&quot;: 0,
48        &quot;react/jsx-filename-extension&quot;: 0,
49        // note you must disable the base rule as it can report incorrect errors
50        &quot;no-shadow&quot;: 0,
51        &quot;@typescript-eslint/no-shadow&quot;: [
52            1
53        ],
54        &quot;no-unused-vars&quot;: 0,
55        &quot;@typescript-eslint/no-unused-vars&quot;: 1,
56        &quot;no-undef&quot;: 0,
57        &quot;jsx-a11y/click-events-have-key-events&quot;: 0,
58        &quot;jsx-a11y/no-static-element-interactions&quot;: 0,
59        &quot;@typescript-eslint/explicit-module-boundary-types&quot;: 0,
60        &quot;react/button-has-type&quot;: 0,
61        &quot;react/require-default-props&quot;: 0,
62        &quot;react/prop-types&quot;: 0,
63        &quot;react-hooks/exhaustive-deps&quot;: 0,
64        &quot;react/jsx-props-no-spreading&quot;: 0
65    },
66    &quot;settings&quot;: {
67        &quot;import/resolver&quot;: {
68            &quot;node&quot;: {
69                &quot;extensions&quot;: [
70                    &quot;.js&quot;,
71                    &quot;.jsx&quot;,
72                    &quot;.ts&quot;,
73                    &quot;.tsx&quot;
74                ]
75            }
76        }
77    }
78}
79import routeNames from 'constants/routeNames';
80import useRoles from 'hooks/roles';
81import { ROLE } from 'shared/src/types/enums';
82  2:24  error  Unable to resolve path to module 'constants/routeNames'    import/no-unresolved
83  3:22  error  Unable to resolve path to module 'hooks/roles'             import/no-unresolved
84  5:22  error  Unable to resolve path to module 'shared/src/types/enums'  import/no-unresolved
85

What am I doing wrong?

ANSWER

Answered 2022-Jan-11 at 17:06

It looks like you have defined custom paths in your TypeScript config (usually tsconfig.json). The import plugin doesn't know about the correct location of the TypeScript config and hence cannot resolve those paths. What you need to do, is to specify the correct path to your TypeScript config via the project parameter in the resolver options:

1{
2    &quot;env&quot;: {
3        &quot;browser&quot;: true,
4        &quot;commonjs&quot;: true,
5        &quot;es6&quot;: true,
6        &quot;node&quot;: true,
7        &quot;jest&quot;: true
8    },
9    &quot;parserOptions&quot;: {
10        &quot;ecmaFeatures&quot;: {
11            &quot;jsx&quot;: true
12        },
13        &quot;sourceType&quot;: &quot;module&quot;
14    },
15    &quot;plugins&quot;: [
16        &quot;react&quot;,
17        &quot;prettier&quot;,
18        &quot;import&quot;
19    ],
20    &quot;extends&quot;: [
21        &quot;airbnb&quot;,
22        &quot;airbnb/hooks&quot;,
23        &quot;plugin:@typescript-eslint/recommended&quot;,
24        &quot;plugin:react/recommended&quot;,
25        &quot;plugin:import/errors&quot;,
26        &quot;plugin:import/warnings&quot;,
27        &quot;plugin:import/typescript&quot;,
28        &quot;prettier&quot;
29    ],
30    &quot;root&quot;: true,
31    &quot;rules&quot;: {
32        &quot;no-const-assign&quot;: 1,
33        &quot;no-extra-semi&quot;: 0,
34        &quot;semi&quot;: 0,
35        &quot;no-fallthrough&quot;: 0,
36        &quot;no-empty&quot;: 0,
37        &quot;no-mixed-spaces-and-tabs&quot;: 0,
38        &quot;no-redeclare&quot;: 0,
39        &quot;no-this-before-super&quot;: 1,
40        &quot;no-unreachable&quot;: 1,
41        &quot;no-use-before-define&quot;: 0,
42        &quot;constructor-super&quot;: 1,
43        &quot;curly&quot;: 0,
44        &quot;eqeqeq&quot;: 0,
45        &quot;func-names&quot;: 0,
46        &quot;valid-typeof&quot;: 1,
47        &quot;import/extensions&quot;: 0,
48        &quot;react/jsx-filename-extension&quot;: 0,
49        // note you must disable the base rule as it can report incorrect errors
50        &quot;no-shadow&quot;: 0,
51        &quot;@typescript-eslint/no-shadow&quot;: [
52            1
53        ],
54        &quot;no-unused-vars&quot;: 0,
55        &quot;@typescript-eslint/no-unused-vars&quot;: 1,
56        &quot;no-undef&quot;: 0,
57        &quot;jsx-a11y/click-events-have-key-events&quot;: 0,
58        &quot;jsx-a11y/no-static-element-interactions&quot;: 0,
59        &quot;@typescript-eslint/explicit-module-boundary-types&quot;: 0,
60        &quot;react/button-has-type&quot;: 0,
61        &quot;react/require-default-props&quot;: 0,
62        &quot;react/prop-types&quot;: 0,
63        &quot;react-hooks/exhaustive-deps&quot;: 0,
64        &quot;react/jsx-props-no-spreading&quot;: 0
65    },
66    &quot;settings&quot;: {
67        &quot;import/resolver&quot;: {
68            &quot;node&quot;: {
69                &quot;extensions&quot;: [
70                    &quot;.js&quot;,
71                    &quot;.jsx&quot;,
72                    &quot;.ts&quot;,
73                    &quot;.tsx&quot;
74                ]
75            }
76        }
77    }
78}
79import routeNames from 'constants/routeNames';
80import useRoles from 'hooks/roles';
81import { ROLE } from 'shared/src/types/enums';
82  2:24  error  Unable to resolve path to module 'constants/routeNames'    import/no-unresolved
83  3:22  error  Unable to resolve path to module 'hooks/roles'             import/no-unresolved
84  5:22  error  Unable to resolve path to module 'shared/src/types/enums'  import/no-unresolved
85{
86    ...
87    &quot;settings&quot;: {
88        &quot;import/resolver&quot;: {
89            &quot;project&quot;: &quot;./my-path-to/tsconfig.json&quot;,
90            ...
91        }
92    }
93}
94

Or if your tsconfig.json is located in your respository's root, set: "project": {}, see this GitHub issue: https://github.com/import-js/eslint-plugin-import/issues/1485

Source https://stackoverflow.com/questions/69199506

QUESTION

Vue 3: Module '&quot;../../node_modules/vue/dist/vue&quot;' has no exported member

Asked 2022-Jan-24 at 08:38

After updating my npm packages, some of the imports from the 'vue' module started showing errors:

TS2305: Module '"../../node_modules/vue/dist/vue"' has no exported member 'X'

where X is nextTick, onMounted, ref, watch etc. When serving the project, Vue says it's "failed to compile". WebStorm actually recognizes the exports, suggests them and shows types, but the error is shown regardless. Some exports like computed and defineComponent work just fine.

What I've tried:

  • Rollback to the previously used Vue version "3.2.2" > "3.0.11". It makes the abovementioned type errors disappear, but the app stops working entirely, showing lots of TypeError: Object(...) is not a function errors in console and not rendering the app at all. In the terminal, some new warnings are introduced: "export 'X' (imported as '_X') was not found in 'vue' where X is createElementBlock, createElementVNode, normalizeClass and normalizeStyle.
  • Rollback other dependencies. None of the ones that I tried helped fix the problem, unfortunately.
  • Manually declare the entirety of 'vue' module. We can declare the 'vue' module exports in shims-vue.d.ts, and it actually makes the errors disappear, however, this seems like a terrible, time-consuming workaround, so I would opt out for a better solution if possible.

My full list of dependencies:

1&quot;dependencies&quot;: {
2   &quot;@capacitor/android&quot;: &quot;3.0.0&quot;,
3   &quot;@capacitor/app&quot;: &quot;1.0.0&quot;,
4   &quot;@capacitor/core&quot;: &quot;3.0.0&quot;,
5   &quot;@capacitor/haptics&quot;: &quot;1.0.0&quot;,
6   &quot;@capacitor/keyboard&quot;: &quot;1.0.0&quot;,
7   &quot;@capacitor/push-notifications&quot;: &quot;^1.0.3&quot;,
8   &quot;@google-pay/button-element&quot;: &quot;^2.5.0&quot;,
9   &quot;@ionic-native/core&quot;: &quot;^5.34.0&quot;,
10   &quot;@ionic-native/qr-scanner&quot;: &quot;^5.35.0&quot;,
11   &quot;@ionic-native/vibration&quot;: &quot;^5.34.0&quot;,
12   &quot;@ionic/vue&quot;: &quot;^5.4.0&quot;,
13   &quot;@ionic/vue-router&quot;: &quot;^5.4.0&quot;,
14   &quot;@j-t-mcc/vue3-chartjs&quot;: &quot;^1.1.2&quot;,
15   &quot;chart.js&quot;: &quot;^3.4.1&quot;,
16   &quot;chartjs-plugin-datalabels&quot;: &quot;^2.0.0&quot;,
17   &quot;color&quot;: &quot;^3.1.3&quot;,
18   &quot;cordova-plugin-background-mode&quot;: &quot;^0.7.3&quot;,
19   &quot;cordova-plugin-device&quot;: &quot;^2.0.3&quot;,
20   &quot;cordova-plugin-qrscanner&quot;: &quot;^3.0.1&quot;,
21   &quot;core-js&quot;: &quot;^3.6.5&quot;,
22   &quot;firebase&quot;: &quot;^8.6.2&quot;,
23   &quot;numeral&quot;: &quot;^2.0.6&quot;,
24   &quot;pug&quot;: &quot;^3.0.2&quot;,
25   &quot;pug-plain-loader&quot;: &quot;^1.1.0&quot;,
26   &quot;secure-ls&quot;: &quot;^1.2.6&quot;,
27   &quot;uuid&quot;: &quot;^8.3.2&quot;,
28   &quot;v-cupertino&quot;: &quot;^1.2.4&quot;,
29   &quot;vue&quot;: &quot;^3.2.0&quot;,
30   &quot;vue-chartjs&quot;: &quot;^3.5.1&quot;,
31   &quot;vue-i18n&quot;: &quot;^9.1.3&quot;,
32   &quot;vue-numerals&quot;: &quot;^4.0.6&quot;,
33   &quot;vue-router&quot;: &quot;^4.0.0-0&quot;,
34   &quot;vuex&quot;: &quot;^4.0.1&quot;
35 },
36 &quot;devDependencies&quot;: {
37   &quot;@capacitor/cli&quot;: &quot;3.0.0&quot;,
38   &quot;@types/jest&quot;: &quot;^24.0.19&quot;,
39   &quot;@types/uuid&quot;: &quot;^8.3.1&quot;,
40   &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^2.33.0&quot;,
41   &quot;@typescript-eslint/parser&quot;: &quot;^2.33.0&quot;,
42   &quot;@vue/cli-plugin-babel&quot;: &quot;~4.5.0&quot;,
43   &quot;@vue/cli-plugin-e2e-cypress&quot;: &quot;~4.5.0&quot;,
44   &quot;@vue/cli-plugin-eslint&quot;: &quot;^4.5.13&quot;,
45   &quot;@vue/cli-plugin-router&quot;: &quot;~4.5.0&quot;,
46   &quot;@vue/cli-plugin-typescript&quot;: &quot;~4.5.0&quot;,
47   &quot;@vue/cli-plugin-unit-jest&quot;: &quot;~4.5.0&quot;,
48   &quot;@vue/cli-service&quot;: &quot;~4.5.0&quot;,
49   &quot;@vue/compiler-sfc&quot;: &quot;^3.0.0-0&quot;,
50   &quot;@vue/eslint-config-typescript&quot;: &quot;^5.0.2&quot;,
51   &quot;@vue/test-utils&quot;: &quot;^2.0.0-0&quot;,
52   &quot;eslint&quot;: &quot;^6.7.2&quot;,
53   &quot;eslint-plugin-vue&quot;: &quot;^7.0.0-0&quot;,
54   &quot;stylus&quot;: &quot;^0.54.7&quot;,
55   &quot;stylus-loader&quot;: &quot;^3.0.2&quot;,
56   &quot;typescript&quot;: &quot;~3.9.3&quot;,
57   &quot;vue-jest&quot;: &quot;^5.0.0-0&quot;
58 }
59

ANSWER

Answered 2021-Aug-15 at 13:53

That named exports from composition API are unavailable means that vue is Vue 2 at some place which has only default export. Since Vue 3 is in dependencies and both lock file and node_modules were refreshed, this means that Vue 2 is nested dependency of some direct dependency.

The problem needs to be investigated in lock file. It shows that @vue/cli-plugin-unit-jest@4.5.13 depends on vue-jest@3 which depends on vue@2.

A possible solution is to upgrade @vue/cli-plugin-unit-jest to the latest version, next. The same likely applies to other @vue/cli-* packages because they have matching versions.

Source https://stackoverflow.com/questions/68790790

Community Discussions contain sources that include Stack Exchange Network

Tutorials and Learning Resources in Jest

Tutorials and Learning Resources are not available at this moment for Jest

Share this Page

share link

Get latest updates on Jest