Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.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
Module TypeScript相对模块名称解析_Module_Typescript - Fatal编程技术网

Module TypeScript相对模块名称解析

Module TypeScript相对模块名称解析,module,typescript,Module,Typescript,我使用TypeScript 1.8并具有以下文件结构: src reducers index.ts someReducer.ts app.tsx 减速机/索引.ts import { combineReducers } from "redux"; import someReducer from "./someReducer"; const appReducer = combineReducers({ someReducer }); export defaul

我使用TypeScript 1.8并具有以下文件结构:

src
  reducers
    index.ts
    someReducer.ts
  app.tsx
减速机/索引.ts

import { combineReducers } from "redux";
import someReducer from "./someReducer";

const appReducer = combineReducers({
    someReducer
});

export default appReducer;
在app.tsx中,我正试图像这样导入它:

import appReducer from "./reducers";
但是,我得到一个错误:

无法将模块“./reducers”归档


我查看了这篇文章,上面说TypeScript将查看文件夹中的
index.ts
,但显然它没有这样做?

index.ts只有在使用
--moduleResolution节点时才会被发现和使用,并且,只有在Node.js中或使用实现与Node.js相同语义的模块加载器时,它才会在运行时工作。(换句话说,最好是显式指定文件,而不是依赖Node.js特定的语义。)

只有在使用
--moduleResolution Node
时才会发现并使用index.ts,并且,只有在Node.js中或使用实现与Node.js相同语义的模块加载器时,它才会在运行时工作。(换句话说,最好是显式指定文件,而不是依赖Node.js特定的语义。)

由于这是标准语法,它如何与ES6兼容?我添加了
“moduleResolution”:“Node”,
t my
tsconfig.json
,这很有帮助,谢谢。ES6没有定义如何解析模块ID。它只定义模块格式。目前还没有任何关于如何实际解析模块的标准(最接近通用互操作标准的是AMD;有一个WHATWG委员会分别对此进行研究)。由于这是标准语法,它如何与ES6兼容?我添加了
“moduleResolution”:“node”,
t my
tsconfig.json
这很有帮助,谢谢。ES6没有定义如何解析模块ID。它只定义模块格式。目前还没有任何关于如何实际解析模块的标准(最接近通用互操作标准的是AMD;有一个WHATWG委员会分别对此进行研究)。