question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v11: and import/reference to useTheme fails in tests: TypeError: stylis.middleware is not a function

See original GitHub issue

Current 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:closed
  • Created 3 years ago
  • Reactions:11
  • Comments:23 (6 by maintainers)

github_iconTop GitHub Comments

23reactions
nisarhassan12commented, Feb 14, 2021

I had a similiar issue in a Next JS project I got if fixed via removing./node_modules and .next and then running yarn install, yarn build and then yarn dev.

4reactions
jereddanielsoncommented, Mar 11, 2021

@Joaoviana @nisarhassan12 thanks for the help! sadly the issue is still there after a bit of mucking around. I’ll need to take a deeper look at some point soon and will update this issue if I find a fix.

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'] from jest.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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found