Module fs-extra doesn't get imported (Dependency issue)

See original GitHub issue

Expected Behavior

I’m configuring a new .ts file for creating a custom action according to this page.

import fs from 'fs-extra'; should import the module defined in the following path: {rootDir}/node_modules/fs-extra

I followed the package.json from this gitrepo and added the module to the {rootDir}/package.json under the section devDepencencies (see image).

image

I also tried adding the dependency at {rootDir}/packages/backend/package.json but that still didn’t work and should be unnecessary.

Actual Behavior

Importing fs-extra from my packages/backend/src/plugins/scaffolder/actions/custom.ts causes the following error:

Could not find a declaration file for module ‘fs-extra’. ‘{root}/node_modules/fs-extra/lib/index.js’ implicitly has an ‘any’ type. Try npm i --save-dev @types/fs-extra if it exists or add a new declaration (.d.ts) file containing declare module 'fs-extra';

I tried to add the package seperately with yarn add fs-extra in both the root and packages/backend directories

The error occured while executing a yarn tsc. It seems like the module is not exported the correct way.  I'm not very familiar with dependencies in javascript frameworks. I tried to declare the module (what the error suggests) but it did nothing for me.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
benjdlambertcommented, Jun 14, 2022

You’ll want to add @types/fs-extra to the devDependencies though. Try adding

    "@types/fs-extra": "^9.0.3",

to devDependencies in packages/backend/package.json and then yarn install should clear up any typescript errors.

1reaction
benjdlambertcommented, Jun 14, 2022

You also probably don’t want to add it to devDependencies if you want to use the package at runtime. fs-extra should be listed in the dependencies section instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support ESM · Issue #746 · jprichardson/node-fs-extra - GitHub
You get an error, because fs-extra is CJS-only. (You cannot export named exports from a CJS file) If we are going to remain...
Read more >
Cannot find module 'fs-extra' npm - node.js - Stack Overflow
My guess is that sudo truffle runs the globally installed truffle and looks for the fs-extra in the global dependencies (where it doesn't...
Read more >
fs-extra - npm
fs -extra contains methods that aren't included in the vanilla Node.js fs package. Such as recursive mkdir, copy, and remove.
Read more >
Cannot find module 'fs' Error in TypeScript | bobbyhadz
To solve the "Cannot find module fs or its corresponding type declarations" error, install the types for node by running the command npm...
Read more >
Dependency resolution - Parcel
js is imported in a browser environment, they'll actually get my-module/fs-browser.js . This applies both to imports from outside (e.g. package sub-paths), as ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found