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

Missing .d.ts files with typescript plugin? #1495

Closed
greggman opened this issue May 16, 2023 · 3 comments
Closed

Missing .d.ts files with typescript plugin? #1495

greggman opened this issue May 16, 2023 · 3 comments

Comments

@greggman
Copy link

Expected Behavior

using rollup -c produces foo.d.ts

Actual Behavior

using rollup -c does not product foo.d.ts even though the foo-impl.d.ts it generates is dependent on foo.d.ts

Additional Information

tsc does produce foo.d.ts

Is this the expected behavior? I'm using rollup to generate a library and some xxx.d.ts files are missing. Wondering how to configure to generate them or if they are not expected to be generated.

@shellscape
Copy link
Collaborator

Please search the issues before opening new ones. This has been covered ad nauseum

@greggman
Copy link
Author

Okay, I looked through every issue here

https://github.com/rollup/plugins/issues?q=is%3Aissue+.d.ts+

Found this one

#1433 (unresovled)

Looked through all 300+ issues here

https://github.com/rollup/plugins/issues?q=is%3Aissue+export

Didn't find a single relevant issue

Looked through all 260+ issues here

https://github.com/rollup/plugins/issues?q=is%3Aissue+typescript

Found this one: #1119 (closed)

This one: #1112 (closed)

This one: #1049

is terse and not at all clear what the solution is supposed to be. I tried modifying my files as seemed to be suggested

diff --git a/rollup.config.js b/rollup.config.js
index a020ec8..fe6ac38 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -5,7 +5,7 @@ export default [
         input: 'src/test.ts',
         output: [
             {
-                file: `dist/test.module.js`,
+                file: `test.module.js`,
                 format: 'esm',
                 sourcemap: true,
             },
diff --git a/tsconfig.json b/tsconfig.json
index cdc1dd6..417fdaf 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -5,6 +5,7 @@
     "module": "esnext",
     "outDir": "dist",
     "declaration": true,
+    "declarationDir": "dist",
   },
   "files": [
     "src/test.ts",

But the correct files did not get written and now my output is in the wrong place.

Someone else in that thread suggested specifying the tsconfig.json so tried that

diff --git a/rollup.config.js b/rollup.config.js
index a020ec8..541b23a 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -11,7 +11,7 @@ export default [
             },
         ],
         plugins: [
-            typescript(),
+            typescript({tsconfig: './tsconfig.json'}),
         ],
     },
 ];
diff --git a/tsconfig.json b/tsconfig.json
index cdc1dd6..417fdaf 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -5,6 +5,7 @@
     "module": "esnext",
     "outDir": "dist",
     "declaration": true,
+    "declarationDir": "dist",
   },
   "files": [
     "src/test.ts",

Still didn't generate the missing files

Saw this issue: #978

Which suggested adding a "declarationDir" though it didn't say where. Tried adding to the typescript() call in rollup.config.json

diff --git a/rollup.config.js b/rollup.config.js
index a020ec8..ac70b3d 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -11,7 +11,7 @@ export default [
             },
         ],
         plugins: [
-            typescript(),
+            typescript({tsconfig: './tsconfig.json', "declarationDir": "dist"}),
         ],
     },
 ];
diff --git a/tsconfig.json b/tsconfig.json
index cdc1dd6..417fdaf 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -5,6 +5,7 @@
     "module": "esnext",
     "outDir": "dist",
     "declaration": true,
+    "declarationDir": "dist",
   },
   "files": [
     "src/test.ts",

No luck

Tried make it "." in both

diff --git a/rollup.config.js b/rollup.config.js
index a020ec8..0ca3b10 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -11,7 +11,7 @@ export default [
             },
         ],
         plugins: [
-            typescript(),
+            typescript({tsconfig: './tsconfig.json', "declarationDir": "."}),
         ],
     },
 ];
diff --git a/tsconfig.json b/tsconfig.json
index cdc1dd6..4beb7a1 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -5,6 +5,7 @@
     "module": "esnext",
     "outDir": "dist",
     "declaration": true,
+    "declarationDir": ".",
   },
   "files": [
     "src/test.ts",

No change, still not generating missing files

This one: #934 seemed irrelevant

This one: #833 (closed)

This one: #247

suggested adding dir: "path" to rollup.config.json output options. That generated

[!] RollupError: Invalid value for option "output.dir" - you must set either "output.file" for a single-file build or "output.dir" when generating multiple chunks.

It also gave a config that worked for someone. I tried applying it

diff --git a/rollup.config.js b/rollup.config.js
index a020ec8..85e5a16 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -5,13 +5,22 @@ export default [
         input: 'src/test.ts',
         output: [
             {
-                file: `dist/test.module.js`,
+                file: `test.module.js`,
                 format: 'esm',
                 sourcemap: true,
             },
         ],
         plugins: [
-            typescript(),
+            typescript({tsconfig: './tsconfig.json', "declarationDir": "."}),
         ],
     },
+    {
+        input: 'src/test.ts',
+        plugins: [
+            typescript({ declaration: true, declarationDir: 'dist' })
+        ],
+        output: [
+            { dir: 'dist', format: 'esm' }
+        ]
+    }
 ];
diff --git a/tsconfig.json b/tsconfig.json
index cdc1dd6..4beb7a1 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -5,6 +5,7 @@
     "module": "esnext",
     "outDir": "dist",
     "declaration": true,
+    "declarationDir": ".",
   },
   "files": [
     "src/test.ts",

No luck, still not generating the missing files

Also tried just having the rule that's supposed to generate the files

diff --git a/rollup.config.js b/rollup.config.js
index a020ec8..a277b00 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -3,15 +3,11 @@ import typescript from '@rollup/plugin-typescript';
 export default [
     {
         input: 'src/test.ts',
-        output: [
-            {
-                file: `dist/test.module.js`,
-                format: 'esm',
-                sourcemap: true,
-            },
-        ],
         plugins: [
-            typescript(),
+            typescript({ declaration: true, declarationDir: 'dist' })
         ],
-    },
+        output: [
+            { dir: 'dist', format: 'esm' }
+        ]
+    }
 ];

No luck. Still not generating the missing files

Looks like this issue: #394

says, it's not supported and not supposed to be supported. Use another tool. Either the ...-dts plugin or tsc itself.

So in the end I ended up with

rollup.config.json

import typescript from '@rollup/plugin-typescript';

export default [
    {
        input: 'src/test.ts',
        output: [
            {
                file: `dist/test.module.js`,
                format: 'esm',
                sourcemap: true,
            },
        ],
        plugins: [
            typescript(),
        ],
    },
];

tsconfig.json

{
  "extends": "@tsconfig/recommended/tsconfig.json",
  "compilerOptions": {
    "target": "ESNext",
    "module": "esnext",
    "outDir": "dist",
  },
  "files": [
    "src/test.ts",
  ],
}

and my build being 2 steps

./node_modules/.bin/rollup -c     
./node_modules/.bin/tsc --emitDeclarationOnly --declaration

(or inside package.json)

  "scripts": {
    "build": "rollup -c && tsc --emitDeclarationOnly --declaration"

@ianyong
Copy link
Contributor

ianyong commented Aug 20, 2023

@greggman I believe #1555 fixes this issue you faced so you can simplify your build step once it's merged. Specifically, you shouldn't need to separately generate type declarations using the TypeScript compiler anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants