Rapsssito / react-native-tcp-socket

React Native TCP socket API for Android, iOS & macOS with SSL/TLS support.
MIT License
304 stars 80 forks source link

Cannot use import statement outside a module #136

Closed aguycalled closed 2 years ago

aguycalled commented 2 years ago

Description

Can't require the module from metro.config.js to resolve net, as it is needed by a third party library.

Steps to reproduce

Project created with npx react-native init.

Contents of metro.config.js:

module.exports = {
  resolver: {
    extraNodeModules: {
      net: require('react-native-tcp-socket'),
    },
  },
};

Current behavior

Error:

error Cannot use import statement outside a module.
/Users/alex/navcash/node_modules/react-native-tcp-socket/src/index.js:3
import Socket from './Socket';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:355:18)
    at wrapSafe (node:internal/modules/cjs/loader:1022:15)
    at Module._compile (node:internal/modules/cjs/loader:1056:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/Users/alex/navcash/metro.config.js:6:12)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
info Run CLI with --verbose flag for more details.

Expected behavior

Module should be loaded

Screenshots If applicable, add screenshots to help explain your problem.

Relevant information

OS macOS 10.15.6
react-native 0.66.4
react-native-tcp-socket 5.5.0
Rapsssito commented 2 years ago

@aguycalled, I am sorry for your issue. However, I do not understand your problem. If you want to resolve react-native-tcp-socket as net, you should add the configuration to your package.json file. Take a look at the docs about overriding net here.

github-actions[bot] commented 2 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community attention? This issue may be closed if no further activity occurs.