coverage-viewer icon indicating copy to clipboard operation
coverage-viewer copied to clipboard

Exception: TypeError: data.map(...).flat is not a function

Open eddex opened this issue 4 years ago • 2 comments

Environment coverage-viewer: 0.4.1 OS: Windows 10 shell: PowerShell npm: 6.13.0 node: v10.16.3

Install output

> npm i -g coverage-viewer

npm WARN deprecated [email protected]: This method has been renamed to "flat" - please use `array.prototype.flat` instead
C:\Users\larry\AppData\Roaming\npm\coverage-viewer -> C:\Users\larry\AppData\Roaming\npm\node_modules\coverage-viewer\cli.js
+ [email protected]
added 108 packages from 65 contributors in 10.354s

Exception

> coverage-viewer "./tests/coverage.json" -s "./src" -o "./viewer"

C:\Users\me\AppData\Roaming\npm\node_modules\coverage-viewer\lib\statistics.js:1
const getAllFiles = data => data.map(project => project.files).flat()
                                                               ^

TypeError: data.map(...).flat is not a function
    at getAllFiles (C:\Users\me\AppData\Roaming\npm\node_modules\coverage-viewer\lib\statistics.js:1:64)
    at exports.getFileStats.data (C:\Users\me\AppData\Roaming\npm\node_modules\coverage-viewer\lib\statistics.js:93:17)
    at renderFile (C:\Users\me\AppData\Roaming\npm\node_modules\coverage-viewer\lib\render.js:34:21)
    at files.map.file (C:\Users\me\AppData\Roaming\npm\node_modules\coverage-viewer\lib\render.js:52:13)
    at Array.map (<anonymous>)
    at Object.exports.renderFiles (C:\Users\me\AppData\Roaming\npm\node_modules\coverage-viewer\lib\render.js:49:16)
    at fs.readFile (C:\Users\me\AppData\Roaming\npm\node_modules\coverage-viewer\lib\render.js:73:13)
    at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)

eddex avatar May 02 '20 11:05 eddex

Seems to be similar to #10

eddex avatar May 02 '20 11:05 eddex

Before this commit the array.prototype.flatten module was used to shim the flatten method on array.prototype. But now the native array.prototype.flat method is being used. However, array.prototype.flat is only available in Node 11+.

Along with updating the call to .flat(), the array.prototype.flat shim should be used for backwards compatibility.

derrickwilliams avatar May 26 '20 17:05 derrickwilliams