Skip to content

Fix conditional import / export of streaming functionality #181

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

Closed
wants to merge 2 commits into from

Conversation

mattt
Copy link
Contributor

@mattt mattt commented Jan 2, 2024

Resolves #179

The stream method introduced by #169 requires a readable stream interface. #172 introduced a conditional import, whereby the library attempts to load the built-in stream module and attempts to fall back on the readable-stream polyfill. However, something about that seems to confuse Next.js (during tree-shaking?), causing it to report an import error in stream when tracing unrelated errors.

This PR refactors this in the following ways:

  • Use import instead of require
  • Export createStream instead of Stream class; the function can throw if Readable isn't found
  • Import node:stream instead of stream to help distinguish use of core module (this was introduced in Node.js 14)

@paramaggarwal
Copy link

Looks good, let's go ahead with merge. Sharing a copy of the error mentioned in #179 as it is an image there and not searchable.

On Next.js 14.1:

./node_modules/replicate/lib/stream.js
Module not found: Can't resolve 'stream' in '/Users/param/Code/poc/node_modules/replicate/lib'
Did you mean './stream'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

Current workaround: install readable-stream npm package.

@paramaggarwal paramaggarwal mentioned this pull request Feb 12, 2024
@mattt
Copy link
Contributor Author

mattt commented Mar 18, 2024

Closing in favor of #214

@mattt mattt closed this Mar 18, 2024
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 this pull request may close these issues.

stream issue ?
2 participants