Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带有经典模块的TypeScript解决方案工作不正确_Javascript_Typescript - Fatal编程技术网

Javascript 带有经典模块的TypeScript解决方案工作不正确

Javascript 带有经典模块的TypeScript解决方案工作不正确,javascript,typescript,Javascript,Typescript,我通过moduleResolution=classic从中学习 typescript编译器按此顺序查找模块 /root/src/folder/moduleB.ts /root/src/folder/moduleB.d.ts /根/src/moduleB.ts /根/src/moduleB.d.ts /根/模B.ts /根/模B.d.ts /模B.ts /模块B.d.ts 但我发现当我使用 从“a”导入{a} 显示找不到模块 我的文件结构是 |--main.ts |--a.ts |--node_模

我通过moduleResolution=classic从中学习

typescript编译器按此顺序查找模块

  • /root/src/folder/moduleB.ts

  • /root/src/folder/moduleB.d.ts

  • /根/src/moduleB.ts

  • /根/src/moduleB.d.ts

  • /根/模B.ts

  • /根/模B.d.ts

  • /模B.ts

  • /模块B.d.ts

  • 但我发现当我使用

    从“a”导入{a}

    显示找不到模块

    我的文件结构是

    |--main.ts

    |--a.ts

    |--node_模块

    仅当我将a.ts放入文件夹node\u modules

    是不是不再支持moduleResolution=classic,还是我的配置有问题?

    中的statet所示:

    模块解析策略经典版:这曾经是TypeScript的默认解析策略。现在,这种策略主要用于向后兼容

    我不知道您的模块是什么样子,但我假设您的
    a.ts
    文件中有类似的内容:

    export default a;
    
    如果是这样,您应该能够像这样导入模块(请注意,对于当前文件夹,路径以“/”开头):


    但是如果您的
    a.ts
    看起来更像这样(没有导出默认值):

    然后您需要像这样导入它:

    import { a } from "./a"
    
    查看有关模块导入的详细信息


    我知道我可以使用相对路径导入它,但我不知道为什么没有相对路径不起作用
    export const a....
    
    import { a } from "./a"