Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to resolve "@socket.io/component-emitter" #1598

Closed
jpgorman opened this issue Nov 20, 2023 · 7 comments
Closed

Unable to resolve "@socket.io/component-emitter" #1598

jpgorman opened this issue Nov 20, 2023 · 7 comments
Labels
documentation Improvements or additions to documentation

Comments

@jpgorman
Copy link

Describe the bug
Using socket.io-client in react native causes a build error

Web Bundling failed 5906ms
Unable to resolve "@socket.io/component-emitter" from "node_modules/socket.io-client/build/esm/manager.js"

To Reproduce

Please fill the following code example:

Socket.io-client version: ^4.7.2

Client

import io from "socket.io-client"; 
...

Expected behavior
To resolve Socket.io-client library modules

Platform:

  • React Native: 0.72.6
  • Metro bundler: 0.76.8
  • Expo: ~49.0.15
  • OS: [e.g. Mac OS 9.2]

Additional context
I did find a work around via the metro bundler config using the following

  const { getDefaultConfig } = require('expo/metro-config');
   /** @type {import('expo/metro-config').MetroConfig} */
   const config = getDefaultConfig(__dirname, {
    ...
   });
   
   
   module.exports = (async () => {
    // add support to implicitly resolve modules with .(c|m)js extensions
    config.resolver.sourceExts.push('cjs');
    config.resolver.sourceExts.push('mjs');
    return config;
   })();
@jpgorman jpgorman added the to triage Waiting to be triaged by a member of the team label Nov 20, 2023
@123zarif
Copy link

I am getting this error. Did anyone found any solution?

@darrachequesne
Copy link
Member

This is weird. The @socket.io/component-emitter package does exist and is listed in the dependencies, so it seems like the bundler is not happy with scoped packages (@socket.io/...).

Is it resolved in newer versions of React Native (0.73.4 currently)?

Possibly related: facebook/react-native#29489

@darrachequesne
Copy link
Member

Source of the @socket.io/component-emitter package: https://github.com/socketio/emitter

@123zarif
Copy link

Did anyone found any solution?

darrachequesne added a commit to socketio/emitter that referenced this issue Apr 10, 2024
In order to remove the .mjs file, which causes some problems with React
Native.

Related: socketio/socket.io-client#1598
@darrachequesne
Copy link
Member

This should be fixed by socketio/emitter@ba6b56d, included in @socket.io/component-emitter@3.1.1.

@jpgorman @123zarif could you please check?

@jpgorman
Copy link
Author

jpgorman commented May 8, 2024

@darrachequesne Thanks for the udpate, yes this does fix the issue with the socket.io-client import for me.

For clarity though it's worth noting that I was also getting similar import issues with other dependencies.

With a little more digging the fix is documented in the metro bundler docs which is demonstrated in the following snippet:

const { getDefaultConfig } = require('expo/metro-config');
const config = getDefaultConfig(__dirname, {
...
});
 
module.exports = (async () => {
  // add support to resolve modules with .(c|m)js extensions
  config.watcher.additionalExts = ['cjs', 'mjs']
  return config;
})();

@darrachequesne
Copy link
Member

@jpgorman awesome, thanks for the update 👍

@darrachequesne darrachequesne added documentation Improvements or additions to documentation and removed to triage Waiting to be triaged by a member of the team labels May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants