Skip to content

compilerOptions.baseUrl in tsconfig.json is not working #933

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

Open
leowux opened this issue May 24, 2025 · 3 comments
Open

compilerOptions.baseUrl in tsconfig.json is not working #933

leowux opened this issue May 24, 2025 · 3 comments

Comments

@leowux
Copy link

leowux commented May 24, 2025

I have the following baseUrl setting in the tsconfig.json in a nextjs project.

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "baseUrl": ".",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "strictNullChecks": true
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}

But TypeScript Native Preview Language server report an error Cannot find module 'app/sitemap' or its corresponding type declarations.ts(2307)

Image

Howerver if I checkout TypeScript Language server, it is working.

Image

@typescript/native-preview: "7.0.0-dev.20250523.1",
Extension Version: 0.20250523.1
@jakebailey
Copy link
Member

baseUrl is unsupported. #474

You should be able to do this same thing with paths, or switch to package.json import maps.

@leowux
Copy link
Author

leowux commented May 24, 2025

@jakebailey I modified baseUrl with paths in tsconfig.

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "paths": {
      "app/*": ["./app/*"]
    },
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "strictNullChecks": true
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}

It is working in file app\robots.ts.

Image

But it is not working in file app\blog\[slug]\page.tsx. Is tsgo not support dynamic segment [slug] as a file name?

Image

@jakebailey
Copy link
Member

I have no idea what would provide those imports. Does this code compile when you run tsc?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants