Skip to content

rewriteRelativeImportExtensions errors on relative import #61615

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

Closed
JakobJingleheimer opened this issue Apr 25, 2025 · 5 comments
Closed

rewriteRelativeImportExtensions errors on relative import #61615

JakobJingleheimer opened this issue Apr 25, 2025 · 5 comments

Comments

@JakobJingleheimer
Copy link

πŸ”Ž Search Terms

rewriteRelativeImportExtensions, monorepo, relative import, file extension

πŸ•— Version & Regression Information

5.8.3

⏯ Playground Link

No response

πŸ’» Code

{
  "compilerOptions": {
    "allowImportingTsExtensions": true,
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "checkJs": true,
    "esModuleInterop": true,
    "incremental": true,
    "isolatedModules": true,
    "lib": [ "dom" ],
    "module": "esnext",
    "moduleResolution": "bundler",
    "noImplicitAny": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strictNullChecks": true,
    "verbatimModuleSyntax": true,
    "baseUrl": "./src",
    "rewriteRelativeImportExtensions": true,
    "outDir": "./build",
    "target": "es2022",
    "resolvePackageJsonExports": true,
    "resolvePackageJsonImports": true,
    "preserveConstEnums": true,
    "useDefineForClassFields": true
  },
  "files": […],
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

πŸ™ Actual behavior

TSC errors (and the error is kind of broken):

error TS2877: This import uses a '.ts' extension to resolve to an input TypeScript file, but will not be rewritten during emit because it is not a relative path.

Found 1 error.

πŸ™‚ Expected behavior

It should work

Additional information about the issue

This occurs in a monorepo like so:

pkgs/
  A
    src/…
    package.json
    tsconfig.json
  B
    src/…
    package.json
    tsconfig.json
  Shared
    src/…
    package.json
    tsconfig.json (config only for VS Code)
tsconfig.json
package.json

A & B get built and published. Shared does not (it is only ever consumed directly by A or B).

// pkgs/A/src/main.ts

import sql from '../../shared/src/helpers/sql.ts';

running tsc in pkgs/A fails, erroneously claiming ../../shared/src/helpers/sql.ts is not a relative path.

@RyanCavanaugh
Copy link
Member

We need something we can clone; "monorepo" does not refer to a single configuration but rather a class of tools and ways of setting things up, the specifics of which are important here.

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Apr 25, 2025
@JakobJingleheimer
Copy link
Author

JakobJingleheimer commented Apr 29, 2025

It's not runnable, but this should give you a more concrete idea: https://github.com/JakobJingleheimer/ts-monorepo-with-shared

If shared is installed via npm or the like, dev mode will work, but when app or server get built, shared will not get transpiled (and specifiers rewritten) per rewriteRelativeImportExtensions's design (not arguing it should). So that option is kinda out the window.

@RyanCavanaugh RyanCavanaugh removed the Needs More Info The issue still hasn't been fully clarified label Apr 30, 2025
@RyanCavanaugh
Copy link
Member

Please open a new issue when you can provide a runnable repo; we don't have resources to guess at what you're doing.

@JakobJingleheimer
Copy link
Author

JakobJingleheimer commented May 3, 2025

You must have misunderstood or I was not clear. The provided repo works perfectly fine for the purposes of this issue. It is not runnable in terms of an app or server you can use.

@JakobJingleheimer
Copy link
Author

Also, some context: this is a continuation of a conversation I had with Jake, who suggested this behaviour may be a bug and requested I open this issue.

I am asking this question because I will be expanding node's guide on using and publishing TypeScript projects (for consumption by node). This helps you as it heads off questions your users would otherwise ask you. Dismissing this issue is not in your interest.

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