-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[V2] dependency missing react-router-dom in gatsby-link #7295
Comments
The newer Gatsby betas have switched over from React Router to Reach Router as it's smaller and has built in accessibility features. It looks like you've updated Gatsby but not your related plugins. I think the following should fix up the error you're seeing:
Check out the migration guide for more info on all the above, there are some other changes you may need to make as you work through the guide. |
Documentation needs to be updated to fix this issue - |
I'm seeing this as well, updating to the newest v2 release, coming from $ yarn why react-router-dom
yarn why v1.7.0
[1/4] 🤔 Why do we have the module "react-router-dom"...?
[2/4] 🚚 Initialising dependency graph...
[3/4] 🔍 Finding dependency...
[4/4] 🚡 Calculating file sizes...
=> Found "[email protected]"
info Reasons this module exists
- "gatsby" depends on it
- Hoisted from "gatsby#react-router-dom"
info Disk size without dependencies: "148MB"
info Disk size with unique dependencies: "668MB"
info Disk size with transitive dependencies: "11.79GB"
info Number of shared dependencies: 20
✨ Done in 1.50s.
$ yarn add gatsby --dev
yarn add v1.7.0
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
warning " > [email protected]" has incorrect peer dependency "react@^16.4.2".
warning " > [email protected]" has incorrect peer dependency "react-dom@^16.4.2".
[4/4] 📃 Building fresh packages...
success Saved lockfile.
success Saved 31 new dependencies.
info Direct dependencies
└─ [email protected]
info All dependencies
├─ @babel/[email protected]
├─ @babel/[email protected]
├─ @types/[email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]
✨ Done in 13.17s.
$ yarn test
...
● Test suite failed to run
Cannot find module 'react-router-dom' from 'blog.spec.jsx'
$ yarn why react-router-dom
yarn why v1.7.0
[1/4] 🤔 Why do we have the module "react-router-dom"...?
[2/4] 🚚 Initialising dependency graph...
[3/4] 🔍 Finding dependency...
error We couldn't find a match!
✨ Done in 1.29s. This was being required to pull in import * as React from 'react';
import { mount, configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { MemoryRouter } from 'react-router-dom';
import Header from './header';
configure({ adapter: new Adapter() });
describe('Header Component', () => {
let header;
beforeEach(() => {
header = mount(
<MemoryRouter>
<Header/>
</MemoryRouter>
).children();
});
it('should not be null', () => {
expect(header).not.toBeNull();
expect(header.find('.header').length).toEqual(1);
});
it('should have a <header> element', () => {
expect(header.find('header').length).toEqual(1);
});
it('should have <h2> element with text', () => {
const heading = header.find('h2');
expect(heading.length).toEqual(1);
expect(heading.text()).toEqual('A DREAMER BY DESIGN');
});
it('should have a link to the home page', () => {
const link = header.find('Link');
expect(link.length).toEqual(1);
expect(link.prop('to').pathname).toEqual('/');
});
}); I recall this was a suggestion from some of the testing conversations at the time. If I try and install react-router-dom manually, I get errors like this Enzyme Internal Error: unknown node with tag 12
11 |
12 | beforeEach(() => {
> 13 | about = mount(
| ^
14 | <MemoryRouter>
15 | <Header/>
16 | </MemoryRouter> @m-allanson |
Hey @thescientist13, experimenting with your tests is looks like you can just plain remove MemoryRouter and the react-router-dom import. However, in a related problem I wasn't able to get your header and navigation specs to find the Link component - not sure what's happening there. |
Thanks @m-allanson for your advice. So I removed references to BeforebeforeEach(() => {
header = mount(
<MemoryRouter>
<Header/>
</MemoryRouter>
).children();
}); AfterbeforeEach(() => {
header = mount(
<Header/>
);
}); But still get that same error about ● Header Component › should have <h2> element with text
TypeError: Cannot read property 'find' of undefined
25 |
26 | it('should have <h2> element with text', () => {
> 27 | const heading = header.find('h2');
| ^
28 |
29 | expect(heading.length).toEqual(1);
30 | expect(heading.text()).toEqual('A DREAMER BY DESIGN');
at Object.<anonymous> (src/components/header/header.spec.jsx:27:28)
● Header Component › should have a link to the home page
Enzyme Internal Error: unknown node with tag 12 So I found this issue and installed latest version of enzyme-adapter-react-16 which helped fix it! 🎉 Now I am just down to these kinds of errors, which I think is what you're seeing too? ● Navigation Component › About link › should only have one About link
expect(received).toBe(expected) // Object.is equality
Expected: 1
Received: 0
47 |
48 | it('should only have one About link', () => {
> 49 | expect(aboutLink.length).toBe(1);
| ^
50 | });
51 |
52 | it('<Link> component should say About', () => {
at Object.<anonymous> (src/components/navigation/navigation.spec.jsx:49:32)
● Navigation Component › About link › <Link> component should say About
Method “text” is only meant to be run on a single node. 0 found instead.
51 |
52 | it('<Link> component should say About', () => {
> 53 | expect(aboutLink.text()).toEqual('About');
| ^
54 | });
55 |
56 | it('should link to the About page', () => {
at ReactWrapper.single (node_modules/enzyme/build/ReactWrapper.js:1532:17)
at ReactWrapper.text (node_modules/enzyme/build/ReactWrapper.js:798:21)
at Object.<anonymous> (src/components/navigation/navigation.spec.jsx:53:24) Will keep plugging away, let me know if you have any other thoughts. I recall |
Old issues will be closed after 30 days of inactivity. This issue has been quiet for 20 days and is being marked as stale. Reply here or add the label "not stale" to keep this issue open! |
This issue is being closed due to inactivity. Is this a mistake? Please re-open this issue or create a new issue. |
Description
I updated my V2 gatsby version today on a working project, after that the compile failed on a missing dependency error.
Steps to reproduce
Update gatsby on a working repo from a previous version(mine was ^2.0.0-beta.54 to ^2.0.0-beta.99)
Expected result
Gatsby project should complile without errors
Actual result
On compile it throws the following error
Environment
File contents (if changed)
gatsby-config.js
: N/Apackage.json
: N/Agatsby-node.js
: N/Agatsby-browser.js
: N/Agatsby-ssr.js
: N/AThe text was updated successfully, but these errors were encountered: