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.

Emotion 11 + React Native + Error While trying to resolve module `stylis`

See original GitHub issue

Current behavior:

I’m using following emotion 11 with React Native 0.63.2, “@emotion/native”: “11.0.0-next.15”, “@emotion/primitives-core”: “11.0.0-next.15”, “@emotion/react”: “11.0.0-next.15”,

And when I build and run I’m getting following error in the runtime,

While trying to resolve module stylis from file /****/node_modules/@emotion/cache/dist/cache.browser.cjs.js, the package /****/node_modules/stylis/package.json was successfully found. However, this package itself specifies a main module field that could not be resolved (/****/node_modules/stylis/dist/stylis.cjs. Indeed, none of these files exist: /****/node_modules/stylis/dist/stylis.cjs(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.svg|.native.svg|.svg)

  • //node_modules/stylis/dist/stylis.cjs/index(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.svg|.native.svg|.svg) at ResolutionRequest.resolveDependency (//node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:65:15) at DependencyGraph.resolveDependency (//node_modules/metro/src/node-haste/DependencyGraph.js:287:16) at Object.resolve (//node_modules/metro/src/lib/transformHelpers.js:267:42) at //node_modules/metro/src/DeltaBundler/traverseDependencies.js:434:31 at Array.map (<anonymous>) at resolveDependencies (//node_modules/metro/src/DeltaBundler/traverseDependencies.js:431:18) at //node_modules/metro/src/DeltaBundler/traverseDependencies.js:275:33 at Generator.next (<anonymous>) at asyncGeneratorStep (//node_modules/metro/src/DeltaBundler/traverseDependencies.js:87:24) at _next (/****/node_modules/metro/src/DeltaBundler/traverseDependencies.js:107:9)

To reproduce:

Use emotion 11 packages with latest react native sample.

Expected behavior:

It should not throw any error.

Environment information:

Reat Native: 0.63.2

"@emotion/native": "11.0.0-next.15",
"@emotion/primitives-core": "11.0.0-next.15",
"@emotion/react": "11.0.0-next.15"

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
arvindellcommented, Sep 1, 2020

Hello, I encountered this issue recently too. The problem is with the stylis depedency as their main module has a cjs extension. The Metro config included in Create React App starter does not include cjs modules by default, so you have to add it as such:

metro.config.js

const { getDefaultConfig } = require('metro-config');

module.exports = (async () => {
  const {
    resolver: { sourceExts, assetExts }
  } = await getDefaultConfig();
  return {
    resolver: {
      sourceExts: [...sourceExts, 'cjs']
    }
  };
})();
1reaction
huetercommented, Sep 4, 2020

Edited: Thank you @efoken

If you’re using Expo try changing your app.json or app.config.(ts|js):

{
    "packagerOpts": {
      "sourceExts": ["cjs"]
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Module not found: Can't resolve '@emotion/react'
I had a similar issue and I resolved it by calling: npm install @emotion/react. or yarn add @emotion/react.
Read more >
Module not found: Can't resolve @emotion/react | bobbyhadz
To solve the error "Module not found: Error: Can't resolve '@emotion/react'", make sure to install the @emotion/react package by opening your terminal in ......
Read more >
can't resolve emotion/ react and styled error solved in material ...
Module not found: Can't resolve '@ emotion / react ' and '@ emotion /styled' solved.
Read more >
Emotion 11
Emotion 11 is a slight evolution over the Emotion 10. It focuses mainly on the developer experience, TS types improvements, switches internals to...
Read more >
@emotion/styled - npm
styled API for emotion. Latest version: 11.10.5, last published: 2 months ago. Start using @emotion/styled in your project by running `npm i ...
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