Skip to content
Closed
Changes from all commits
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
7 changes: 6 additions & 1 deletion packages/create-vite/template-preact-ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

"baseUrl": "./",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this baseUrl needed? The downside with this is that TypeScript would autocomplete imports as "src/components/..." (note leading src/), which wouldn't work in Vite ootb.

Copy link
Copy Markdown
Author

@AJamesPhillips AJamesPhillips Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah interesting, I didn't know that thanks. I'm using the baseUrl in this vitejs project: github.com/AJamesPhillips/conversation-helper and when I use VisualStudio code to add a missing import it adds as a relative path like "./components/LogList". How do you recreate the autocomplete imports as "src/..." is this a setting I have set that I'm now unaware of perhaps?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It usually happens when you have a very long path of ../../../../../../ and TS intelligently picks the short src/components/.. path instead. But anyways, setting this baseUrl also let TS resolves correctly without warnings, so a user who manually type that (for any reason) would falsely think it works too.

Copy link
Copy Markdown
Author

@AJamesPhillips AJamesPhillips Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Makes sense. I just wish there was a more descriptive error message to point you towards adding "baseUrl" and "paths" to tsconfig.json

Sounds like you don't want this contribution so I'll close this PR. Thanks for your time and help understanding this better 🙂

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do want the paths contribution! Just not the baseUrl part. Is the baseUrl required for paths to work?

Copy link
Copy Markdown
Author

@AJamesPhillips AJamesPhillips Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. I misunderstood. In my own project it seems I can remove "baseUrl" and the following still work without error: imports, type checking, and vite dev/build. So I will hesitantly say yes but I don't really know why preact would recommend adding baseUrl if it wasn't needed.

"paths": {
"react": ["./node_modules/preact/compat/"],
"react-dom": ["./node_modules/preact/compat/"]
},

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
Expand Down