jszip icon indicating copy to clipboard operation
jszip copied to clipboard

Module not found: Error: Can't resolve 'stream' in 'xxx\node_modules\jszip\lib'

Open catamphetamine opened this issue 4 years ago • 2 comments

For some reason, it requires stream when bundled with Webpack.

ERROR in ./node_modules/jszip/lib/readable-stream-browser.js 9:0-34
Module not found: Error: Can't resolve 'stream' in 'xxx\node_modules\jszip\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
        - install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "stream": false }
 @ ./node_modules/jszip/lib/support.js 35:27-62
 @ ./node_modules/jszip/lib/index.js 40:16-36
 @ blah blah blah

webpack 5.15.0 compiled with 1 error in 688 ms
i 「wdm」: Failed to compile.

catamphetamine avatar Jan 19 '21 11:01 catamphetamine

This is fixable by updating the 'browser' section of package.json to include "stream": "stream-browserify"

DanielHeath avatar Jan 20 '21 02:01 DanielHeath

This issue can be closed. I suspect this issue was fixed by #742, at least this problem is present in release 3.5.0 but not in 3.6.0.

Verification:

$ ng new jszip-test
? Would you like to add Angular routing? No
? Which stylesheet format would you like to use? CSS
...
$ cd jszip-test/
$ ng test --watch=false
...
TOTAL: 3 SUCCESS

$ npm install [email protected]
...
$ echo "import * as JSZip from 'jszip';" >> src/app/jszip.spec.ts
$ echo "var zip = new JSZip();" >> src/app/jszip.spec.ts
$ ng test --watch=false
√ Browser application bundle generation complete.

./node_modules/jszip/lib/readable-stream-browser.js:9:0-34 - Error: Module not found: Error: Can't resolve 'stream' in 'C:\test\jszip-test\node_modules\jszip\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
        - install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "stream": false }


17 10 2022 16:05:25.252:INFO [karma-server]: Karma v6.4.1 server started at http://localhost:9876/
17 10 2022 16:05:25.256:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
17 10 2022 16:05:25.268:INFO [launcher]: Starting browser Chrome
17 10 2022 16:05:26.185:INFO [Chrome 106.0.0.0 (Windows 10)]: Connected on socket 8ZMpW4xQLJuiCWJ7AAAB with id 66557292
17 10 2022 16:05:26.275:WARN [web-server]: 404: /_karma_webpack_/main.js
Chrome 106.0.0.0 (Windows 10): Executed 0 of 0 SUCCESS (0.006 secs / 0 secs)
TOTAL: 0 SUCCESS

$ npm install [email protected]
...
$ ng test --watch=false
...
TOTAL: 3 SUCCESS

$

hlovdal avatar Oct 17 '22 14:10 hlovdal