lzutf8.js icon indicating copy to clipboard operation
lzutf8.js copied to clipboard

CAn't build with Angular: Can't resolve 'stream' in ./node_modules/lzutf8/build/production/lzutf8.js

Open barakbbn opened this issue 4 years ago • 9 comments

It seems the Angular WebPack build is not happy about the require('stream') in lzutf8.js and 'stream' package is not declared as dependency nor installed manually.

Should consider separating LZ-UTF8 package to 2 packages, for client and Node, Or somehow avoiding this issue without forcing Angular developers installing the 'stream' package event if not going to use it

barakbbn avatar Dec 02 '19 12:12 barakbbn

Hi, "stream" is built-in part of the Node.js standard library (not an external package): https://nodejs.org/api/stream.html

It is dynamically imported when needed (only when a particular method is called and when running in the Node.js environment).

I see WebPack is trying to resolve that dependency. I'm not quite familiar with WebPack to give advice on how to work around that. A quick search lead to this issue on the tracker. One of the comments links to this solution to ignore a module in a particular environment. I'm not sure yet if it would help putting it in the package.json of the published library itself. Need to explore further.

rotemdan avatar Dec 02 '19 14:12 rotemdan

npm install stream resolved the issue, however, this step should not be needed..

ghost avatar Mar 23 '20 15:03 ghost

Same here

jimmykane avatar Sep 06 '20 10:09 jimmykane

I think my PR might address this issue too. It adds a dependency to 'readable-stream' (which is more compatible) and also instructs npm/yarn to install with package. https://github.com/rotemdan/lzutf8.js/pull/30

jcbdev avatar Jan 12 '21 09:01 jcbdev

Thanks for the PR. I'm still a bit confused why referencing node's own stream module has become so problematic. I guess that back when the library was initially written (2014) it was mostly about supporting either the browser or the Node environments. Today there's all sort of wrappers and libraries that attempt to emulate some of each's features, causing compatibility issues.

I'll merge the pull request and see what needs to be done from there.

rotemdan avatar Jan 12 '21 16:01 rotemdan

Latest PR breaks for any applications that use rollup to bundle, see: https://github.com/nodejs/readable-stream/issues/348

ispyinternet avatar Jan 25 '21 16:01 ispyinternet

@ispyinternet I have published the PR to a minor version (0.5.8). This may have been a mistake since adding the new dependency could be seen as a breaking change. I've now published version 0.6.0 with a minor unrelated change.

I'm considering unpublishing 0.5.8 (to at least ensure that rollup users would get a broken minor update) but I'm not sure if that's a good idea.

Sorry about my month-late response. I have been busy lately.

rotemdan avatar Feb 24 '21 16:02 rotemdan

The build is not browser compatible, but the readme file provides the browser option which makes it confusing.

JennieJi avatar Oct 22 '21 04:10 JennieJi