vinyl-fs icon indicating copy to clipboard operation
vinyl-fs copied to clipboard

[DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.

Open kashav opened this issue 1 year ago • 1 comments

Before you open this issue, please complete the following tasks:

  • [x] use the search bar at the top of the page to search this repository for similar issues or discussions that have already been opened.
  • [ ] if you are looking for help from the gulp team or community, open a discussion.
  • [ ] if you think there is a problem with the plugin you're using, open a discussion.
  • [x] if you think there is a bug in our code, open this issue.

What were you expecting to happen?

No deprecation warning.

What actually happened?

Deprecation warning for the fs.Stats constructor.

Please give us a sample of your gulpfile

// src/zip.js
import gulp from 'gulp'
import zip from 'gulp-zip'
import { createRequire } from 'module'
const require = createRequire(import.meta.url)
const manifest = require('../build/manifest.json')

gulp
  .src('build/**')
  .pipe(zip(`${manifest.name.replaceAll(' ', '-')}-${manifest.version}.zip`))
  .pipe(gulp.dest('package'))

Terminal output / screenshots

$ node --trace-deprecation src/zip.js
(node:59666) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.
    at Transform.normalize [as _transform] (/node_modules/vinyl-fs/lib/dest/prepare.js:38:32)
    at Transform._write (/node_modules/streamx/index.js:981:12)
    at WritableState.update (/node_modules/streamx/index.js:187:16)
    at WritableState.updateWriteNT (/node_modules/streamx/index.js:550:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)

Please provide the following information:

  • OS & version [e.g. MacOS Catalina 10.15.4]: n/a
  • node version (run node -v): v22.3.0
  • npm version (run npm -v): 10.8.1
  • gulp version (run gulp -v): CLI version: 3.0.0 / Local version: 5.0.0

Additional information

API was deprecated in Node v22.0.0 - https://nodejs.org/api/deprecations.html#DEP0180:

Calling fs.Stats class directly with Stats() or new Stats() is deprecated due to being internals, not intended for public use.

Docs also mention:

Stat objects are not to be created directly using the new keyword.

Not sure what the alternative is here. Maybe just use fs.statSync() or return an empty object if the file doesn't exist?

kashav avatar Aug 19 '24 22:08 kashav

This library currently supports node 10+. This cannot be resolved until older node support is dropped.

phated avatar Aug 19 '24 22:08 phated