Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

baseUrl definition in tsconfig.json leads to compilation error #35131

Open
Wassap124 opened this issue Nov 15, 2019 · 1 comment
Open

baseUrl definition in tsconfig.json leads to compilation error #35131

Wassap124 opened this issue Nov 15, 2019 · 1 comment
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@Wassap124
Copy link

Wassap124 commented Nov 15, 2019

I've been experiencing weird import bugs,
despite defining baseUrl in my tsconfig.json (as shown below), imports don't work.
I am not using webpack, babel, etc. (That's why I am opening this issue, the others I've seen were problems regarding webpack and such).

// tsconfig.json
{
  "compilerOptions": {
    "target": "es6",                         
    "module": "commonjs",                    
    "lib": ["es6","dom"],                    
    "sourceMap": true,                     
    "outDir": "./dist",                      
    "rootDir": "./src",                      
    "strict": true,                          
    "noImplicitAny": true,                 
    "baseUrl": "src",                        
    "esModuleInterop": true,                 
    "resolveJsonModule": true,               
    "forceConsistentCasingInFileNames": true 
  },
  "exclude": ["node_modules"]
}
//routers/games.ts
import GameController from "controllers/games";
import Router from "koa-router";

export const gamesRouter = new Router()
    .get("/", (ctx) => {
        ctx.body = GameController.getGames();
    });
// controllers/games.ts
export default class GameController {

    public static getGames = () => {
        return [];
    }
}

Project tree

.
├── package.json
├── src
│   ├── config.ts
│   ├── controllers
│   │   └── games.ts
│   ├── index.ts
│   └── routers
│       └── games.ts
├── tsconfig.json
├── tslint.json
└── yarn.lock 

Expected behavior:
absolute imports with src defined as root should work.
project should compile
Actual behavior:

Error: Cannot find module 'controllers/games'
@andrewbranch
Copy link
Member

I can’t reproduce this—what you’ve shared looks right. Can you share a repo that exhibits the issue?

@andrewbranch andrewbranch added the Needs More Info The issue still hasn't been fully clarified label Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

2 participants