Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module 'undici-types' when running npx tsc .\Program.fs.ts --target es2022 #3612

Closed
blfuentes opened this issue Nov 25, 2023 · 2 comments

Comments

@blfuentes
Copy link

blfuentes commented Nov 25, 2023

Description

I'm trying to follow the Getting Started tutorial with typescript but I'm getting lot of errors when I run the command npx tsc Program.fs --target es2022 proposed in the Step 04 of Typescript.

Repro code

  • Follow the Getting Started tutorial up to the Step 04 of Typescript.
  • Then try to run npx tsc Program.fs --target es2022 as indicated
  • Try to run the correct command npx tsc Program.fs.ts --target es2022

Expected and actual results

The proposed command is invalid as npx doesn't work with a .fs extension. It has to be modified to run Program.fs.ts

> npx tsc .\Program.fs --target es2022
error TS6054: File 'Program.fs' has an unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'.
  The file is in the program because:
    Root file specified for compilation

So I try to run the corrected command: npx tsc Program.fs.ts --target es2022 expecting the code to be compiled.
But I get the following errors:

> npx tsc .\Program.fs.ts --target es2022
node_modules/@types/node/globals.d.ts:325:84 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

325         type _Request = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Request;
                                                                                       ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:326:85 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

326         type _Response = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Response;
                                                                                        ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:327:85 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

327         type _FormData = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").FormData;
                                                                                        ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:328:84 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

328         type _Headers = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Headers;
                                                                                       ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:330:22 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

330             : import("undici-types").RequestInit;
                         ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:336:35 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

336         type RequestInfo = import("undici-types").RequestInfo;
                                      ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:337:35 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

337         type HeadersInit = import("undici-types").HeadersInit;
                                      ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:338:32 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

338         type BodyInit = import("undici-types").BodyInit;
                                   ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:339:39 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

339         type RequestRedirect = import("undici-types").RequestRedirect;
                                          ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:340:42 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

340         type RequestCredentials = import("undici-types").RequestCredentials;
                                             ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:341:35 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

341         type RequestMode = import("undici-types").RequestMode;
                                      ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:342:38 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

342         type ReferrerPolicy = import("undici-types").ReferrerPolicy;
                                         ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:343:34 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

343         type Dispatcher = import("undici-types").Dispatcher;
                                     ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:344:37 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

344         type RequestDuplex = import("undici-types").RequestDuplex;
                                        ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:360:21 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

360     : typeof import("undici-types").Request;
                        ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:367:21 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

367     : typeof import("undici-types").Response;
                        ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:374:21 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

374     : typeof import("undici-types").FormData;
                        ~~~~~~~~~~~~~~

node_modules/@types/node/globals.d.ts:381:21 - error TS2792: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

381     : typeof import("undici-types").Headers;
                        ~~~~~~~~~~~~~~


Found 18 errors in the same file, starting at: node_modules/@types/node/globals.d.ts:325

Related information

I have tried installing the undici and undici-types but no success:

package.json

{
  "name": "sleeptracker",
  "version": "1.0.0",
  "type": "module",
  "description": "",
  "main": "Program.fs.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/node": "^20.10.0",
    "typescript": "^5.3.2",
    "undici": "^5.28.0",
    "undici-types": "^5.28.0"
  }
}

tsconfig.json

{
    "compilerOptions": {
        "module": "NodeNext",
        "moduleResolution": "NodeNext"
    }
}

folder structure
image

  • Fable version: dotnet fable --version : 4.5.0
  • Typescript: 5.3.2
  • .net 8
  • node 21.2.0
  • Operating system: Windows 10 22h2
@MangelMaxime
Copy link
Member

Hello @blfuentes,

Indeed there was a typo in the command line provided.

To get rid of the undici-types error, you need to add --skipLibCheck to the command line (it is the default when creating a tsconfig.json).

So the command to run becomes: npx tsc Program.fs.ts --target es2022 --skipLibCheck

I fixed the documentation, please re-open if this doesn't fix your issue.

Note: Using --skipLibCheck will not make you code less typed, it just tells TypeScript to not check/compiles the types inside the definition file as they should have been already been done correctly by the author. Plus it saves some compilation time because the compiler has less to do

@blfuentes
Copy link
Author

Thanks! works perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants