question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find module 'fs-extra/esm' or its corresponding type declarations.ts(2307)

See original GitHub issue

Both importing from fs-extra and fs-extra/esm doesn’t work anymore in v11.0.0. I tried the following lines in my fs.ts file:

import { ensureDirSync, ensureFileSync, removeSync } from 'fs-extra'
import { ensureDirSync, ensureFileSync, removeSync } from 'fs-extra/esm'

The top line does work in v10.1.0. Am I doing something wrong?

  • Operating System: Ubuntu 22.04.1 LTS
  • Node.js version: v16.18.0
  • fs-extra version: v11.0.0

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
caugnercommented, Nov 29, 2022

@RyanZim I just had a quick skim through https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html and found this:

One more wrinkle, TypeScript does not (yet) behave with exports. So you need to include the legacy module and main properties for TypeScript. The main property points to the CJS entry point and the module property points to the ESM entry.

Based on that, this should work:

{
  "main": "./lib/index.js",
  "module": "./lib/esm.mjs",
  "exports": {
    "import": "./lib/esm.mjs",
    "require": "./lib/index.js"
  }
}

In other words, removing main from package.json may have removed TypeScript support.

Update: Just double checked, and those changes resolve the issue with TypeScript.

(Background: https://github.com/mdn/yari/pull/7697)

0reactions
RyanZimcommented, Nov 29, 2022

Based on a quick look through the package.jsons in our dependency tree, you’re using the exports field differently that most packages. For most packages, the value for . inside exports is an object with keys import/types/default.

Yeah, this is shorthand notation: https://nodejs.org/api/packages.html#exports-sugar I’m curious if changing it to an object with only default would also fix TS support (not sure I want to do that as the actual fix, as it’s non-intuitive). Based on this, it seems this would be a potential bug that TS should fix?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find module or its corresponding type declarations ...
About the declaration for your parser you could use the pegjs/typings/generated-parser.d.ts from your node modules as a starting point.
Read more >
cannot find module 'yup' or its corresponding type declarations ...
The code editor is showing the error mentioned in the title (Cannot find module 'global.module.css' or its corresponding type declarations.ts(2307)) ...
Read more >
error TS2307: Cannot find module 'type-fest/source/simplify' or ...
Updating to version 7.36.1 breaks our build with the following error npm install type-fest --save-dev appears to be a workaround, ...
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 >
Custom Widget: Cannot find module or its correspon...
I have written a widget using JS API 4.16/TypeScript and I'm ... Widget: Cannot find module or its corresponding type declarations.ts(2307).
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