简体   繁体   English

如何修复未找到 tsconfig.json 模块?

[英]How to fix tsconfig.json module not found?

I have the following folder structure:我有以下文件夹结构:

\---src  
|   \---test
|   |   \---login
|   |       index.ts
|   \---utils
|       |   utilsFuntion.ts

i want to import the utilsFuntion from utils filder under src inside the login folder like this way: import {somefuntion} from 'utils/utilsFuntion';我想从登录文件夹中 src 下的 utils 文件导入 utilsFuntion,如下所示: import {somefuntion} from 'utils/utilsFuntion';

instead of doing like this: import {somefuntion} from '../../../utils/utilsFuntion';而不是这样做: import {somefuntion} from '../../../utils/utilsFuntion';

here is my tsconfig file:这是我的 tsconfig 文件:

{
    "compilerOptions": {
        "target": "es6",
        "lib": ["dom", "dom.iterable", "esnext"],
        "strict": true,
        "module": "commonjs",
        "noEmit": true,
        "resolveJsonModule": true,
        "esModuleInterop": true,
        "baseUrl": "src",
        "paths": {
          "src/*": ["src/*"]
        }
    },
    "include": ["src"]
}

after i add the src baseUrl and the paths i change the import like this: import {somefuntion} from 'utils/utilsFuntion';在我添加 src baseUrl 和路径后,我将导入更改如下: import {somefuntion} from 'utils/utilsFuntion'; i got error that say: Error: Cannot find module 'utils/helpFunction我收到错误提示: Error: Cannot find module 'utils/helpFunction

any idea how to fix this?知道如何解决这个问题吗?

i try:我尝试:

./utils/utilsFuntion.ts
./utils/utilsFuntion
utils/utilsFuntion.ts
src/utils/utilsFuntion.ts
src/utils/utilsFuntion

You can refer this using absolute paths in typescript for imports您可以使用 typescript 中的绝对路径进行导入

Try this尝试这个

import {somefuntion} from '@src/utils/utilsFuntion';

In the tsconfig在 tsconfig

"paths": {
      "@src/*": ["./src/*"]
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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