v11: and import/reference to useTheme fails in tests: TypeError: stylis.middleware is not a function
See original GitHub issueCurrent behavior:
I’ve upgraded to the wonderful v11 (thanks for your great work, btw!). Alas, any attempt to import useTheme
from within
a [jest] test fails for me with TypeError: stylis.middleware is not a function
.
To reproduce:
# useTheme.test.ts
import { useTheme } from '@emotion/react';
it('should be defined', () => {
expect(useTheme).toBeDefined(); // FAILS: TypeError: stylis.middleware is not a function
});
Note that just the import + reference to useTheme
fails, we’re not even invoking useTheme()
here.
Environment information:
react
version: 17.0.1@emotion/react
version: 11.0.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:23 (6 by maintainers)
Top Results From Across the Web
TypeError: stylis middleware is not a function - Stack Overflow
Trying to run a test, but an error was thrown (TypeError: stylis.middleware is not a function), anyone has faced same issue before?
Read more >TypeError: middleware is not a function — React + Redux + ...
Hello. I am relatively a beginner to React. There is a tutorial I followed to create a project, and I got stuck at...
Read more >Experts for omit lodash - Linknovate
Name Score News
GitHub 85.1 8
Dave Gibbons Ltd. 68.8 3
Conflict Resolution 54.2 2
Read more >ASP.NET Core 2 and Angular 5
The "No executable found matching command dotnet-ef" error ... This is a test to see if the StaticFiles middleware is working properly.
Read more >Untitled
Vertolkt betekenis, Graf duckula emma, Cos x function graph, Baman piderman ... Scheepmakersstraat, Fontspec error font-not-found linux, Aval varuvala video ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had a similiar issue in a Next JS project I got if fixed via removing
./node_modules
and.next
and then runningyarn install
,yarn build
and thenyarn dev
.Not sure if it’s relevant to you but I was able to solve the issue described on this page by checking my Jest config and removing
moduleDirectories: ['.', 'src', 'node_modules']
fromjest.config.js
. I’m not sure why that line was there originally, tests seem to run fine without it and finally solves my problem with emotion v11.I’d recommend going through your Jest config line by line - remove a line, run tests, see if it helps. That’s literally what I did and it helped narrow down the problem.
Good luck.