简体   繁体   中英

error TS6231: Could not resolve the path '' with the extensions: '.ts', '.tsx', '.d.ts'

I'm working on firebase functions with typescript and this error appears in the console while running tsc. -watch tsc. -watch :

[12:19:41 PM] Starting compilation in watch mode...

error TS6231: Could not resolve the path '' with the extensions: '.ts', '.tsx', '.d.ts'.
  The file is in the program because:
    Root file specified for compilation

[12:19:45 PM] Found 1 error. Watching for file changes.

I have no idea where this might be arising from. I haven't changed anything since the last time this was working.

Any solutions?

当我使用 tsc init 而不是 tsc --init 时出现此错误

Try to compile the project indicating the path of tsconfig.json (configuration file) or the directory where it is. Using --project.

tsc --project tsconfig.json

or

tsc --project ./

Here in this link tsc CLI Options you can find more options to compile your project.

试试tsc -watch ,它为我解决了这个问题

I was seeing this same error and it was obfuscating the real error under the covers.

Try compiling your typescript in one step, and then running the entry file as the second step. So essentially, not in watch mode.


FWIW, the error that was actually occurring for me was a failure of the code to read my environment variables. I traced it to an update from dotenv that broke the ability for NODE_ENV to be properly set (on a Windows machine) in my startup script.

from my experience, when you create a new tsconfig.json, there is like

,
  "files": [
    "\\",
    "\\"
  ]

in the bottom. so I just removed it, and that's solve my problem.

我必须在项目中安装打字稿

将文件名从 .tsc 更改为 .ts 即可:)

Follow this link, it worked for me: https://bobbyhadz.com/blog/typescript-could-not-resolve-path-with-extensions-ts-tsx

This block to be specific: For example, if you issue a command tsc init, the TypeScript compiler thinks that you want to emit JS for a file called init. Instead, you should use the init flag, tsc --init.

Try to remove "files" in the bottom of the archive. It worked for me.

Compile with:

tsc

And not with:

tsc . // remove the dot

So update package.json to:

"script: {
   "build": "rm -rf build && tsc", // delete build folder then complile
}

remove "files": [""] use "rootDir": "./src", "outDir": "./output" keepall.ts files inside 'src' folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM