Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2646,7 +2646,7 @@ function loadModuleFromExports(scope: PackageJsonInfo, extensions: Extensions, s
}

function loadModuleFromImports(extensions: Extensions, moduleName: string, directory: string, state: ModuleResolutionState, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): SearchResult<Resolved> {
if (moduleName === "#" || startsWith(moduleName, "#/")) {
if (moduleName === "#") {
if (state.traceEnabled) {
trace(state.host, Diagnostics.Invalid_import_specifier_0_has_no_possible_resolutions, moduleName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
index.cts(2,21): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#/foo.js")' call instead.
index.cts(3,21): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#/features/bar.js")' call instead.
index.cts(4,21): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#/nested/deep/baz.js")' call instead.


==== package.json (0 errors) ====
{
"name": "package",
"private": true,
"type": "module",
"imports": {
"#/*": "./src/*"
}
}
==== src/foo.ts (0 errors) ====
export const foo = "foo";
==== src/features/bar.ts (0 errors) ====
export const bar = "bar";
==== src/nested/deep/baz.ts (0 errors) ====
export const baz = "baz";
==== index.ts (0 errors) ====
// esm format file
import { foo } from "#/foo.js";
import { bar } from "#/features/bar.js";
import { baz } from "#/nested/deep/baz.js";
foo;
bar;
baz;
==== index.mts (0 errors) ====
// esm format file
import { foo } from "#/foo.js";
import { bar } from "#/features/bar.js";
import { baz } from "#/nested/deep/baz.js";
foo;
bar;
baz;
==== index.cts (3 errors) ====
// cjs format file
import { foo } from "#/foo.js";
~~~~~~~~~~
!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#/foo.js")' call instead.
import { bar } from "#/features/bar.js";
~~~~~~~~~~~~~~~~~~~
!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#/features/bar.js")' call instead.
import { baz } from "#/nested/deep/baz.js";
~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("#/nested/deep/baz.js")' call instead.
foo;
bar;
baz;

Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//// [tests/cases/conformance/node/nodeModulesPackageImportsRootWildcard.ts] ////

//// [package.json]
{
"name": "package",
"private": true,
"type": "module",
"imports": {
"#/*": "./src/*"
}
}
//// [foo.ts]
export const foo = "foo";
//// [bar.ts]
export const bar = "bar";
//// [baz.ts]
export const baz = "baz";
//// [index.ts]
// esm format file
import { foo } from "#/foo.js";
import { bar } from "#/features/bar.js";
import { baz } from "#/nested/deep/baz.js";
foo;
bar;
baz;
//// [index.mts]
// esm format file
import { foo } from "#/foo.js";
import { bar } from "#/features/bar.js";
import { baz } from "#/nested/deep/baz.js";
foo;
bar;
baz;
//// [index.cts]
// cjs format file
import { foo } from "#/foo.js";
import { bar } from "#/features/bar.js";
import { baz } from "#/nested/deep/baz.js";
foo;
bar;
baz;


//// [foo.js]
export const foo = "foo";
//// [bar.js]
export const bar = "bar";
//// [baz.js]
export const baz = "baz";
//// [index.js]
// esm format file
import { foo } from "#/foo.js";
import { bar } from "#/features/bar.js";
import { baz } from "#/nested/deep/baz.js";
foo;
bar;
baz;
//// [index.mjs]
// esm format file
import { foo } from "#/foo.js";
import { bar } from "#/features/bar.js";
import { baz } from "#/nested/deep/baz.js";
foo;
bar;
baz;
//// [index.cjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// cjs format file
const foo_js_1 = require("#/foo.js");
const bar_js_1 = require("#/features/bar.js");
const baz_js_1 = require("#/nested/deep/baz.js");
foo_js_1.foo;
bar_js_1.bar;
baz_js_1.baz;


//// [foo.d.ts]
export declare const foo = "foo";
//// [bar.d.ts]
export declare const bar = "bar";
//// [baz.d.ts]
export declare const baz = "baz";
//// [index.d.ts]
export {};
//// [index.d.mts]
export {};
//// [index.d.cts]
export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//// [tests/cases/conformance/node/nodeModulesPackageImportsRootWildcard.ts] ////

=== src/foo.ts ===
export const foo = "foo";
>foo : Symbol(foo, Decl(foo.ts, 0, 12))

=== src/features/bar.ts ===
export const bar = "bar";
>bar : Symbol(bar, Decl(bar.ts, 0, 12))

=== src/nested/deep/baz.ts ===
export const baz = "baz";
>baz : Symbol(baz, Decl(baz.ts, 0, 12))

=== index.ts ===
// esm format file
import { foo } from "#/foo.js";
>foo : Symbol(foo, Decl(index.ts, 1, 8))

import { bar } from "#/features/bar.js";
>bar : Symbol(bar, Decl(index.ts, 2, 8))

import { baz } from "#/nested/deep/baz.js";
>baz : Symbol(baz, Decl(index.ts, 3, 8))

foo;
>foo : Symbol(foo, Decl(index.ts, 1, 8))

bar;
>bar : Symbol(bar, Decl(index.ts, 2, 8))

baz;
>baz : Symbol(baz, Decl(index.ts, 3, 8))

=== index.mts ===
// esm format file
import { foo } from "#/foo.js";
>foo : Symbol(foo, Decl(index.mts, 1, 8))

import { bar } from "#/features/bar.js";
>bar : Symbol(bar, Decl(index.mts, 2, 8))

import { baz } from "#/nested/deep/baz.js";
>baz : Symbol(baz, Decl(index.mts, 3, 8))

foo;
>foo : Symbol(foo, Decl(index.mts, 1, 8))

bar;
>bar : Symbol(bar, Decl(index.mts, 2, 8))

baz;
>baz : Symbol(baz, Decl(index.mts, 3, 8))

=== index.cts ===
// cjs format file
import { foo } from "#/foo.js";
>foo : Symbol(foo, Decl(index.cts, 1, 8))

import { bar } from "#/features/bar.js";
>bar : Symbol(bar, Decl(index.cts, 2, 8))

import { baz } from "#/nested/deep/baz.js";
>baz : Symbol(baz, Decl(index.cts, 3, 8))

foo;
>foo : Symbol(foo, Decl(index.cts, 1, 8))

bar;
>bar : Symbol(bar, Decl(index.cts, 2, 8))

baz;
>baz : Symbol(baz, Decl(index.cts, 3, 8))

Loading
Loading