0

I use TypeScript 1.8 and have the following file structure:

src
  reducers
    index.ts
    someReducer.ts
  app.tsx

reducers/index.ts

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

const appReducer = combineReducers({
    someReducer
});

export default appReducer;

In app.tsx I am trying to import it like this:

import appReducer from "./reducers";

However, I get an error:

Cannot file module './reducers'

I checked the Modules Resolution article, which says that TypeScript will look into index.ts in the folder, but apparently it does not?

1 Answer 1

2

index.ts will only be discovered and used if you are using --moduleResolution node, and it will only work at runtime if you are in Node.js or using a module loader that implements the same semantics as Node.js. (In other words, you are really better off explicitly specifying the file, instead of relying on Node.js-specific semantics.)

Sign up to request clarification or add additional context in comments.

3 Comments

How does it correspond with ES6 compatibility since this is the standard syntax there?
I added "moduleResolution": "node", t my tsconfig.json and it helped, thanks.
ES6 does not define how module IDs are resolved. It only defines the module format. There is not currently any standard regarding how to actually resolve modules (the closest thing to an common interoperable standard is AMD; there is a WHATWG committee working on this separately).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.