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 module stream #1196

Open
boh001 opened this issue Jan 20, 2024 · 4 comments
Open

Unable to resolve module stream #1196

boh001 opened this issue Jan 20, 2024 · 4 comments

Comments

@boh001
Copy link

boh001 commented Jan 20, 2024

lm developiing in pnpm workspace. when I use the unstable_enablePackageExports option, I get the following error. whats wrong?

error: Error: Unable to resolve module stream from /Users/sanghyeon/projects/plzsub/node_modules/.pnpm/ws@8.16.0/node_modules/ws/lib/stream.js: stream could not be found within the project or in these directories:
  ../../../node_modules/.pnpm/ws@8.16.0/node_modules
  ../../../node_modules
  1 | 'use strict';
  2 |
> 3 | const { Duplex } = require('stream');
    |                             ^
  4 |
  5 | /**
  6 |  * Emits the `'close'` event on a stream.
    at ModuleResolver.resolveDependency (/Users/sanghyeon/projects/plzsub/node_modules/.pnpm/metro@0.80.3/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:153:15)
    at DependencyGraph.resolveDependency (/Users/sanghyeon/projects/plzsub/node_modules/.pnpm/metro@0.80.3/node_modules/metro/src/node-haste/DependencyGraph.js:279:43)
    at /Users/sanghyeon/projects/plzsub/node_modules/.pnpm/metro@0.80.3/node_modules/metro/src/lib/transformHelpers.js:176:21
    at resolveDependencies (/Users/sanghyeon/projects/plzsub/node_modules/.pnpm/metro@0.80.3/node_modules/metro/src/DeltaBundler/buildSubgraph.js:56:25)
    at visit (/Users/sanghyeon/projects/plzsub/node_modules/.pnpm/metro@0.80.3/node_modules/metro/src/DeltaBundler/buildSubgraph.js:107:30)
    at async Promise.all (index 1)
    at async visit (/Users/sanghyeon/projects/plzsub/node_modules/.pnpm/metro@0.80.3/node_modules/metro/src/DeltaBundler/buildSubgraph.js:116:5)
    at async Promise.all (index 8)
    at async visit (/Users/sanghyeon/projects/plzsub/node_modules/.pnpm/metro@0.80.3/node_modules/metro/src/DeltaBundler/buildSubgraph.js:116:5)
    at async Promise.all (index 0)

this is my metro config

/* eslint-disable @typescript-eslint/no-var-requires */
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
const path = require('path');

const watchFolders = [
  path.resolve(path.join(__dirname, '../../../node_modules')),
  path.resolve(path.join(__dirname, '../../../packages')),
];

/**
 * Metro configuration
 * https://facebook.github.io/metro/docs/configuration
 *
 * @type {import('metro-config').MetroConfig}
 */
const config = {
  resolver: {
    unstable_enablePackageExports: true,
  },
  watchFolders,
};

module.exports = mergeConfig(getDefaultConfig(__dirname), config);

this is my dev env

os: mac ventura 13.6.3
reac-native: 0.73.2
pnpm: 8.13.1
node: 20.10.0

thank you :)

@robhogan
Copy link
Contributor

robhogan commented Jan 20, 2024

Hi @boh001. ws is a WebSocket implementation for Node.js, and not compatible (or necessary) for the browser or React Native (which has a native WebSocket global).

If you're not importing ws directly it might be a dependency of one of your dependencies.

If you have a require stack, we can see why it's being imported. It may be that an intermediate dependency is resolving to a Node.js version.

@boh001
Copy link
Author

boh001 commented Jan 21, 2024

@robhogan thank you for reply. I think that's all there is to the require stack

error: Error: Unable to resolve module stream from /Users/sanghyeon/projects/plzsub/node_modules/.pnpm/ws@8.16.0/node_modules/ws/lib/stream.js: stream could not be found within the project or in these directories:
  ../../../node_modules/.pnpm/ws@8.16.0/node_modules
  ../../../node_modules
  1 | 'use strict';
  2 |
> 3 | const { Duplex } = require('stream');
    |                             ^
  4 |
  5 | /**
  6 |  * Emits the `'close'` event on a stream.
    at ModuleResolver.resolveDependency (/Users/sanghyeon/projects/plzsub/node_modules/.pnpm/metro@0.80.3/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:153:15)
    at DependencyGraph.resolveDependency (/Users/sanghyeon/projects/plzsub/node_modules/.pnpm/metro@0.80.3/node_modules/metro/src/node-haste/DependencyGraph.js:279:43)
    at /Users/sanghyeon/projects/plzsub/node_modules/.pnpm/metro@0.80.3/node_modules/metro/src/lib/transformHelpers.js:176:21
    at resolveDependencies (/Users/sanghyeon/projects/plzsub/node_modules/.pnpm/metro@0.80.3/node_modules/metro/src/DeltaBundler/buildSubgraph.js:56:25)
    at visit (/Users/sanghyeon/projects/plzsub/node_modules/.pnpm/metro@0.80.3/node_modules/metro/src/DeltaBundler/buildSubgraph.js:107:30)
    at async Promise.all (index 1)
    at async visit (/Users/sanghyeon/projects/plzsub/node_modules/.pnpm/metro@0.80.3/node_modules/metro/src/DeltaBundler/buildSubgraph.js:116:5)
    at async Promise.all (index 8)
    at async visit (/Users/sanghyeon/projects/plzsub/node_modules/.pnpm/metro@0.80.3/node_modules/metro/src/DeltaBundler/buildSubgraph.js:116:5)
    at async Promise.all (index 0)

but i dont understand why it doesn't work when unstable_enablePackageExports is enabled. i guess if problem is ws as you said, It should have been equally bad when this option is disabled, but it works.

thank you :)

@robhogan
Copy link
Contributor

but i dont understand why it doesn't work when unstable_enablePackageExports is enabled. i guess if problem is ws as you said, It should have been equally bad when this option is disabled, but it works.

It's probably upstream of ws - my guess is that you have a dependency which only requires ws when running under Node.js, and it's the entry point to that dependency that's being resolved differently with unstable_enablePackageExports. You'd need to find out what's requiring ws - pnpm why ws might have some clues.

@boh001
Copy link
Author

boh001 commented Jan 23, 2024

pnpm why ws shows nothing. it's so weird.
for now, it looks like the only way is to disable this option. is it okay to leave the issue open for people have the same problem? Maybe someone will solve it one day :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants