簡體   English   中英

TypeScript相對模塊名稱解析

[英]TypeScript relative module names resolution

我使用TypeScript 1.8,並且具有以下文件結構:

src
  reducers
    index.ts
    someReducer.ts
  app.tsx

減速器/ index.ts

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

const appReducer = combineReducers({
    someReducer
});

export default appReducer;

app.tsx中,我試圖像這樣導入它:

import appReducer from "./reducers";

但是,我得到一個錯誤:

無法歸檔模塊“ ./reducers”

我查看了Modules Resolution文章,該文章說TypeScript將調查文件夾中的index.ts ,但顯然不是嗎?

僅當您使用--moduleResolution node ,才會發現和使用index.ts,並且僅當您在Node.js中或使用實現與Node.js相同語義的模塊加載器時,index.ts才在運行時起作用。 (換句話說,您最好顯式地指定文件,而不是依賴於Node.js特定的語義。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM