0

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

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

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

Import declaration conflicts with local declaration of 'fsExtra'

enter image description here

How to solve the issue?

Raphael10
  • 2,508
  • 7
  • 22
  • 50
  • Don't reuse the name. `import fsExtra from 'fs-extra'` – Quentin Dec 08 '22 at 11:04
  • Hi @Quentin ! Thanks for helping. I imported `fs-extra` in this way: `import fs from 'fs-extra'` : Is it correct, or if wrong, how to correctly import `fs-extra` ? – Raphael10 Dec 08 '22 at 11:07
  • I literally gave you the revised code in my previous comment. – Quentin Dec 08 '22 at 11:08
  • Sorry @Quentin . With `import fsExtra from 'fs-extra'` I get the same error: `Import declaration conflicts with local declaration of 'fsExtra'` ( I updated my post above) – Raphael10 Dec 08 '22 at 11:13
  • @Quentin based on here: https://github.com/jprichardson/node-fs-extra#commonjs we could use both `import fs from 'fs-extra'` and `import fse/fsExtra from 'fs-extra'` – Raphael10 Dec 08 '22 at 11:17

0 Answers0