jprichardson / node-fs-extra

Node.js: extra methods for the fs object like copy(), remove(), mkdirs()
MIT License
9.44k stars 776 forks source link

Import declaration conflicts with local declaration of 'fs' #984

Closed raphael10-collab closed 1 year ago

raphael10-collab commented 1 year ago

I'm getting this error:

Import declaration conflicts with local declaration of 'fs'

in main :

import fs from 'fs-extra'

fs.ensureDir(settingsUserDataFolder, err => {
  console.log(err)
})

If I comment this part:

//fs.ensureDir(settingsUserDataFolder, err => {
  //console.log(err)
//})

the error disappears

With import fsExtra from 'fs-extra' I get the same error:

Import declaration conflicts with local declaration of 'fsExtra'

image

In webpack.main.config.js :

const fs = require('fs-extra')

module.exports = {
  // https://webpack.js.org/configuration/externals/#externalstypecommonjs
  externalsType: 'commonjs',
  externals: {
    'fs': 'fs-extra',
  }
};

ts.config.json :

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "display": "Node 16",
  "compilerOptions": {
    "allowJs": true,
    "lib": ["es2021", "dom", "dom.iterable"], // https://www.e-learn.cn/topic/3468143
    "module": "commonjs",
    "target": "es2019",
    "skipLibCheck": true,
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "jsx": "react",
    "noImplicitAny": false,
    "sourceMap": true,
    "baseUrl": "./src",
    "outDir": "dist",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "paths": {
      "@app/*": ["app/*"],
      "*": ["node_modules/*"]
    }
  },
  "include": ["./src/**/*"]
}

Other Info:

"typescript": "^4.9.3",
"electron": "^17.2.0",
"@electron-forge/plugin-webpack": "6.0.0-beta.63",
"@types/fs-extra": "^9.0.13",
 "fs-extra": "^11.1.0",

node: v18.12.1
O.S.: Ubuntu 22.04 Desktop

How to solve the issue?

RyanZim commented 1 year ago

You have a rather complicated setup, with a number of moving parts. We have TS, Webpack, & Electron. I'd suggest trying to create a reduced test case with the minimum number of moving parts. Try removing Webpack or Electron from the equation, and see if you still have a problem. Chances are, you'll uncover the source of the bug in the process.

raphael10-collab commented 1 year ago

Thank you @RyanZim for your kind suggestion. I will do it, and let you know

In the meanwhile, I'm using standard fs (node : v 18) without any issues

RyanZim commented 1 year ago

Assuming this is resolved.