TypeScript: Imports in index.ts file are not getting correctly resolved.
"typescript": "3.2.2"
Imports in index.ts file are not getting correctly imported. Inside engine folder, I have files as
- engine
- index.ts
- engine.ts
- test.ts
Inside index.ts, I have
export { Engine } from ‘./engine’; export { Test } from ‘./test’;
When I try to import, Engine class in another file using
import {Engine} from ‘…/engine’;
engine is not defined
I get it correct if I write this way.
import {Engine} from '../engine/engine';
This was working fine previously, but after resent ts version upgrade it is giving this error.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 22 (3 by maintainers)
try setting
"moduleResolution": "node"incompilerOptionsof yourtsconfig.jsonYou have to add a slash in the folder (module) name, this will treat index.ts as the folder index.
import {Engine} from '../engine/';Any recommendations available for writing exports in index.ts and using the exported modules internnally ? … this issue is really frustrating to debug : (…
I’m having a similar issue when using
baseUrl: "src"Obs: the error is shown when the file is open, but the code runs smoothly. The import actually works. Maybe VSCode TS intellisense is the one to blame here.
Project structure:
Test results from
component.tsxThis is the error:
This is my
tsconfig.jsonfile:TS version:
"typescript": "^4.5.5"Obs: This is happening inside my
packages/adminproject. This is a monorepo using Yarn workspaces. Not sure if this is related or not. TypeScript is installed at the root of the workspace (but I think this error is coming from VSCode TS itself).@coderbuzz first of all, thank you. You’ve saved my sanity.
Second of all, are there docs/is this common knowledge/where is this learned if you had not been here? I certainly didn’t see it in module resolution docs.