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.

[React Native] Can't find variable: __dirname

See original GitHub issue

I simply added

import useSWR from 'swr'

then error occurred Can’t find variable: __dirname __dirname is on compiled dist code, but React Native doesn’t support _dirname.

Issue Analytics

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

github_iconTop GitHub Comments

8reactions
shudingcommented, Nov 27, 2019

The current cache structure needs some refactoring to support async cache mechanisms. And after that, we will be able to support custom cache APIs like AsyncStorage.

2reactions
90dycommented, Nov 21, 2019

The __dirname variable is located in node_modules/swr/dist/index.js I need to import swr/esm to bypass it

Read more comments on GitHub >

github_iconTop Results From Across the Web

[React Native] Can't find variable: __dirname #137 - GitHub
I am facing a similar issue but when importing it from import useSWR from '@zeit/swr' it works fine @n3tr Thanks for maintaining this....
Read more >
React Native ReferenceError Can't find variable - Stack Overflow
I am trying to use the tag instead of and it this gives no reference found error. Code : import React, {Component} from...
Read more >
ReferenceError: Can't find variable: useAuth - React Native
Assuming that you are working on the “DoneWithIt” app for react Native: you should have a module here: /app/auth/useAuth.js.
Read more >
Alternatives to __dirname in Node.js with ES modules
The new __dirname and __filename variables created in the code above work just like in CommonJS — if you pass them around, they'll...
Read more >
Using Next.js with Expo for Web
Next.js is a React framework that provides simple page-based routing as well as server-side rendering. To use Next.js with Expo for web we...
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