lambda-packages icon indicating copy to clipboard operation
lambda-packages copied to clipboard

🐛 BUG: Astro does not work in projects with `"moduleResolution": "Node16"`

Open Alxandr opened this issue 3 years ago • 3 comments

What version of astro are you using?

1.0.0-rc.6

Are you using an SSR adapter? If so, which one?

N/A

What package manager are you using?

pnpm

What operating system are you using?

linux

Describe the Bug

If you setup a typescript project to use the new node-resolution algorithm for finding files (and typings), importing astro gives Could not find a declaration file for module 'astro'.

image

Note: the stackblitz only shows the error in the editor when hovering over the import in the file src/lib/test.ts.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-yhqnoe-xh7qcy?file=src/lib/test.ts

Participation

  • [x] I am willing to submit a pull request for this issue.

Alxandr avatar Aug 05 '22 19:08 Alxandr

I did some poking around in the code, and it seems to me that all that's needed is some minor changes to the tsconfig and package.json file:

diff --git a/packages/astro/package.json b/packages/astro/package.json
index d5ee1cbcf..cb673374b 100644
--- a/packages/astro/package.json
+++ b/packages/astro/package.json
@@ -12,14 +12,14 @@
   },
   "bugs": "https://github.com/withastro/astro/issues",
   "homepage": "https://astro.build",
-  "types": "./dist/types/@types/astro.d.ts",
+  "types": "./dist/@types/astro.d.ts",
   "typesVersions": {
     "*": {
       "app": [
-        "./dist/types/core/app/index"
+        "./dist/core/app/index"
       ],
       "app/*": [
-        "./dist/types/core/app/*"
+        "./dist/core/app/*"
       ]
     }
   },
diff --git a/packages/astro/tsconfig.json b/packages/astro/tsconfig.json
index 58e865c0c..a51690d2a 100644
--- a/packages/astro/tsconfig.json
+++ b/packages/astro/tsconfig.json
@@ -3,7 +3,7 @@
   "include": ["src", "index.d.ts"],
   "compilerOptions": {
     "allowJs": true,
-    "declarationDir": "./dist/types",
+    "declarationDir": "./dist",
     "module": "ES2020",
     "outDir": "./dist",
     "target": "ES2020",

I can create a PR if this seems like a reasonable solution.

Alxandr avatar Aug 05 '22 20:08 Alxandr

Hmm, interesting! I don't think I see any downsides to moving the declarationDir up a level. Will let @Princesseuh weigh in as the resident TS expert!

natemoo-re avatar Aug 05 '22 22:08 natemoo-re

Small update, i also had to update one of the lines in the exports map. I'll make a PR so you can see the full working diff easier. I've tested it locally using pnpm link.

Alxandr avatar Aug 06 '22 07:08 Alxandr