Search code examples
javascripttypescriptecmascript-6es6-module-loader

require() to import throws error: Cannot read property 'createsocket' of undefined


When I use require the import works correctly:

let dgram = require('react-native-udp')

But when I try to use the same as import:

import dgram from 'react-native-udp'

I get error: Cannot read property 'createsocket' of undefined

When I look inside its dir in node_modules this is what I get:

enter image description here

I also tried:

  import {dgram} from 'react-native-udp'

But get same error


Solution

  • Try :

    import * as dgram from 'react-native-udp'