tradle / rn-nodeify

hack to allow react-native projects to use node core modules, and npm modules that use them
MIT License
614 stars 114 forks source link

[BUG] ReferenceError: Can't find variable: __dirname #109

Closed JonasHiltl closed 2 years ago

JonasHiltl commented 2 years ago

I use a package that uses __dirname but when running the app I get the error ReferenceError: Can't find variable: __dirname. The line below is the conflicting one:

const path = require('path').join(__dirname, 'identity_wasm_bg.wasm');

This is my shim.js. And as I understand it shim.js should set the variable __dirname globally, so it should be available in the package that uses __dirname. But I still get a ReferenceError.

if (typeof __dirname === 'undefined') global.__dirname = '/'
if (typeof __filename === 'undefined') global.__filename = ''
if (typeof process === 'undefined') {
  global.process = require('process')
} else {
  const bProcess = require('process')
  for (var p in bProcess) {
    if (!(p in process)) {
      process[p] = bProcess[p]
    }
  }
}

process.browser = false
if (typeof Buffer === 'undefined') global.Buffer = require('buffer').Buffer

// global.location = global.location || { port: 80 }
const isDev = typeof __DEV__ === 'boolean' && __DEV__
process.env['NODE_ENV'] = isDev ? 'development' : 'production'
if (typeof localStorage !== 'undefined') {
  localStorage.debug = isDev ? '*' : ''
}

These are my dependencies to shim:

"postinstall": "rn-nodeify --install fs,util,process,path,events,stream --hack --yarn"
JonasHiltl commented 2 years ago

I forgot to import shim.js