TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Self-reference / import of the current package doesn't work in an mjs file, but does in a ts file in src

Open jakebailey opened this issue 3 years ago • 0 comments

Bug Report

node16 nodenext esm mjs self reference referential module package name

🔎 Search Terms

🕗 Version & Regression Information

  • This is the behavior in every version I tried

💻 Code

Repro here: https://github.com/jakebailey/self-reference-mjs

In short, I have a mjs file with:

// @ts-check

import * as index from "self-reference-mjs";

console.log(index.foo);

And a package.json like:

  "name": "self-reference-mjs",
  "version": "1.0.0",
  "type": "module",
  "exports": {
    ".": "./dist/index.js"
  },

This code executes and does the right thing, but TS gives an error on the import. Writing the same code in a TS file works, but the emitted code is identical to the hand-written code.

🙁 Actual behavior

I can import the current package by name in an mjs file.

🙂 Expected behavior

I can only import the current package in TS, not in an mjs file.

I sort of expected this to work post #46762 or something, but the behavior is inconsistent.

jakebailey avatar Aug 11 '22 03:08 jakebailey