ion icon indicating copy to clipboard operation
ion copied to clipboard

`sst.config.ts` TypeScript experience sensitive to `moduleResolution` setting

Open sockthedev opened this issue 1 year ago • 3 comments

This is probably more of a note than anything else. Maybe some docs / defaults on the topic would do.

Steps to reproduce.

mkdir ion-module-resolution-sensitive
cd ion-module-resolution-sensitive
pnpm init
sst init

Add the following tsconfig:

{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
  }
}

I also updated my package.json slightly, although I don't think this has any impact:

{
  "name": "ion-module-resolution-sensitive",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "sst": "ion"
  },
  "devDependencies": {
    "@types/aws-lambda": "8.10.140",
    "@types/node": "^20.14.9",
    "typescript": "5.5.3"
  }
}

Go into sst.config.ts. Types not working.

Make the following change to tsconfig:

 {
   "compilerOptions": {
     "module": "NodeNext",
-    "moduleResolution": "NodeNext",
+    "moduleResolution": "Bundler",
   }
 }

Now sst.config.ts types are working.


Why do I use "moduleResolution": "NodeNext"?

I find the "Bundler" setting results in an inconsistent experience, around the file extension being included, when auto resolving import statements. I'm trying to force my code to obey ESM rules to avoid any annoying refactors in the future. Took me a while to identify that as the culprit.

sockthedev avatar Jul 06 '24 00:07 sockthedev