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

Could not resolve "stream" #7

Open
vlovich opened this issue Jan 31, 2022 · 2 comments · May be fixed by #9
Open

Could not resolve "stream" #7

vlovich opened this issue Jan 31, 2022 · 2 comments · May be fixed by #9

Comments

@vlovich
Copy link

vlovich commented Jan 31, 2022

I'm trying to build my TypeScript project using ES Modules with ESBuild (not targeting node) and it's failing with

✘ [ERROR] Could not resolve "stream"

    node_modules/rfc2047/node_modules/iconv-lite/lib/extend-node.js:167:35:
      167 │             var Readable = require('stream').Readable;
          ╵                                    ~~~~~~~~

  The package "stream" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

✘ [ERROR] Could not resolve "stream"

    node_modules/rfc2047/node_modules/iconv-lite/lib/streams.js:1:24:
      1 │ var Transform = require("stream").Transform;
        ╵                         ~~~~~~~~

  The package "stream" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

#5 seemed similar so I'm wondering if there's an issue with this project + ESBuild (and or ES Modules)?

@vlovich
Copy link
Author

vlovich commented Jan 31, 2022

I found this helped the package not be found:

  var iconvLite;
  var iconv;
  try {
    const pkgName = 'iconv-lite';
    iconvLite = require(pkgName);
    iconv = require('' + 'iconv'); // Prevent browserify from detecting iconv and failing
  } catch (e) {}

However, I'm wondering if there might be a way to have iconv support be completely optional. When I look at the generated output, there's still iconv branches live which means the tree shaking isn't able to perform dead code elimination.

@papandreou
Copy link
Collaborator

Happy to take contributions that would help with this situation.

@vlovich vlovich linked a pull request Feb 1, 2022 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants