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

rewriteRelativeImportExtensions with import mjs file into mts file => TS2876: This relative import path is unsafe #60396

Closed
d00rsfan opened this issue Nov 3, 2024 · 0 comments Β· Fixed by #60415
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@d00rsfan
Copy link

d00rsfan commented Nov 3, 2024

πŸ”Ž Search Terms

rewriteRelativeImportExtensions
ts(2876)

πŸ•— Version & Regression Information

  • This changed between versions NA and 5.7.0-dev.20241103 or 5.7.0-beta

⏯ Playground Link

No response

πŸ’» Code

//src/logger/logger.mjs
//File is JS mjs file!

const logger = (message) => {
  console.log(message)
}
export default logger;

src/database/database.mts
//File is TS mts file!

import logger from '../logger/logger.mjs';

// tsconfig.json, fragment

{
  "compilerOptions": {
    "target": "ESNext",
    "lib": [
      "esnext"
    ],
    "allowJs": true,
    "esModuleInterop": true,
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "rewriteRelativeImportExtensions": true,
    "resolveJsonModule": true,
  }
}

// "package.json does not have any type overriding because project explicitly uses the correct filename extensions."

πŸ™ Actual behavior

import mjs in mts file
TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "../ logger/ logger. mjs"

But works good

  • on import .mjs into mjs files.
  • on import .mts files into both, mjs and mts.

πŸ™‚ Expected behavior

No error emitted. imported filename and extension is correct.

Additional information about the issue

Reproduced on both, 5.7.0-beta and current ^5.7.0-dev.20241103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
4 participants