Skip to content

nodenext doesn't pick up on addition of type field to package.json #50086

Closed
@DanielRosenwasser

Description

@DanielRosenwasser

Here's a quick way you can clone this repro locally

https://github.com/DanielRosenwasser/daniel-ts-repros/
cd daniel-ts-repros
git checkout nodenext-package-watch-bug

// src/fileA.ts
import { foo } from "./fileB.mjs";

foo();
// src/fileB.mts
export function foo() {
}
// src/tsconfig.json
{
  "compilerOptions": {
    "target": "es2016",
    "module": "Node16",
    "outDir": "../out"
  }
}
// package.json

{
  "name": "nodenext-package-watch-bug",
  "version": "1.0.0",
  "description": "Repro",
  "author": "Daniel"
}

Currently this produces the following result in the editor or in --watch mode:

Module './fileB.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.ts

If you add a "type": "module" to the package.json, then the error will not go away until you restart tsc or TS Server.

-  "author": "Daniel"
+  "author": "Daniel",
+  "type": "module"

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Node ESMLike ES Modules, but specific to Node.js support (cts, cts, mjs, mts)Fix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions