rollup-plugin-ts icon indicating copy to clipboard operation
rollup-plugin-ts copied to clipboard

Subpaths imports syntax not working

Open imjuni opened this issue 3 years ago • 2 comments

  • Version: 3.1.1
  • Rollup Version: 3.9.1
  • Operating System and version (if applicable): wsl2
  • Node Version (if applicable): 14.20.1
  • Does it work with tsc (if applicable): fine works in tsc

Reproduction

I create reproducable repo. Reproducable problem that step,

  1. checkout reproducable repo.
  2. run npm install
  3. run npm run rollup:prod

Expected Behavior

Recently, Node.js and TypeScript support subpaths imports. This feature can replace TypeScript Re-Map paths and tsconfig-paths.

But rollup-plugin-ts cannot compile this syntax like that,

[!] (plugin Typescript) RollupError: Cannot find module '#modules/logger.js' or its corresponding type declarations.

I think that rollup-plugin-ts have to do compile this syntax.

Actual Behavior

rollup-plugin-ts cannot resolve this syntax. rollup-plugin-ts display error message like that,

[!] (plugin Typescript) RollupError: Cannot find module '#modules/logger.js' or its corresponding type declarations.

imjuni avatar Jan 12 '23 00:01 imjuni

@wessberg is it possible to support moduleResolution: node16 or moduleResolution: nodenext instead of forced moduleResolution: node?

quebits avatar Feb 09 '23 17:02 quebits

@quebits as a temporary workaround patching dist/cjs/index.cjs and/or dist/esm/index.js to use Bundler rather than NodeJs fixes this for me (NodeNext works as well, but it breaks most published modules and doesn't work with dual/mixed CommonJS/ESM packages):

diff --git a/dist/cjs/index.cjs b/dist/cjs/index.cjs
--- a/dist/cjs/index.cjs
+++ b/dist/cjs/index.cjs
@@ -746,7 +746,7 @@ function getForcedCompilerOptions(options) {
         // Node resolution is required when 'importHelpers' are true
-        moduleResolution: options.pluginOptions.typescript.ModuleResolutionKind.NodeJs,
+        moduleResolution: options.pluginOptions.typescript.ModuleResolutionKind.Bundler,
diff --git a/dist/esm/index.js b/dist/esm/index.js
--- a/dist/esm/index.js
+++ b/dist/esm/index.js
@@ -744,7 +744,7 @@ function getForcedCompilerOptions(options) {
         // Node resolution is required when 'importHelpers' are true
-        moduleResolution: options.pluginOptions.typescript.ModuleResolutionKind.NodeJs,
+        moduleResolution: options.pluginOptions.typescript.ModuleResolutionKind.Bundler,

chocolateboy avatar May 16 '23 17:05 chocolateboy