Closed tiavina-mika closed 3 months ago
@tiavina-mika is this a general question about monorepo setup or are you starting from a specific example that we provide and it's broken out of box?
Slightly similar case but with with-svelte
starter.
If you remove the import statement from apps/web/src/routes/+page.svelte
and try to auto import MyCounterButton
, vscode doesnt give you autocompletion. I suppose paths should be properly configured in the starter packs beforehand.
I solved it with a vscode plugin named Svelte Auto Import
(by pivaszbs)
Auto Import
plugin by steoates didn't work.
(offtopic: don't forget to run turbo dev
at least once, otherwise .svelte-kit
doesnt generate just with pnpm install
. related)
I was trying to migrate to turbo and i think this is present with the basic examples
The above repo is created with npx create-turbo -e basic
and then follow the steps in Sharing code docs to add a new package (ui
package's autoimport works but it's using build files from tsup
so I won't touch from that).
Then in the apps
repo you can't auto import the math functions
// apps/docs/app/page.tsx
export default function Page(): JSX.Element {
// NOTE: can't auto import this
add()
Also something that is confusing me is that while the above sharing code section mentions that you need to create a tsconfig.json
for said shared package, in this blog by turbo (You might not need TypeScript project references) it's stated that an internal package should have a package.json
but no tsconfig.json
. Not sure if which one the correct configuration in this case
I faced the same problem when using VSCode.
I tried to modify the apps/docs/tsconfig.json
by adding:
"include": ["../../packages/ui/src/**/*.tsx"]
It's working now but I am not sure this is the good way to deal with it or not.
best solution i found is add the following to tsconfig.json
"include": [
"src/**/*.ts",
"src/**/*.svelte",
"node_modules/@repo/**/*.svelte",
"node_modules/@repo/**/*.ts"
]
basically just add the paths to the repo dependencies that your app depends on. Make sure they are in dependencies or devDependencies in pacakge.json and you have installed.
I am currently facing the same issue. I tried solution from @hoaibao44 and it works (but same I am not sure if it's a good solution to deal with the problem).
@SeanDem I tried also yours but it's not working if node_modules
is excluded.
Do you know If there is a way to include subfolders even if a parent folder is excluded?
I tried with files
as suggested here https://github.com/Microsoft/TypeScript/issues/17228 but it's not working on my side
I was having problems with auto importing and it all comes down to how my package.json files are set up.
Most likely you are missing "exports" in your package.json file
here is an what's in my package.json file for a shadcn package I have.
"type": "module",
"exports": {
"./globals.css": "./src/globals.css",
"./lib/*": "./src/lib/*.ts",
"./components/ui/*": "./src/components/ui/*.tsx",
"./hooks/*": "./src/hooks/*.ts"
},
now if I was building the package I would have it like this:
"files": [
"dist"
],
"main": "./dist/cjs/index.js",
"module": "./dist/es/index.mjs",
"types": "./dist/cjs/index.d.ts",
"exports": {
"import": {
"types": "./dist/es/index.d.ts",
"default": "./dist/es/index.js"
},
"require": {
"types": "./dist/cjs/index.d.cts",
"default": "./dist/cjs/index.cjs"
}
},
I am building with tsup in this example, but you can use other build libraries too.
note: do not modify your tsconfig files to include other packages. That is a weird hack and you will run into problems with that approach.
@rtorcato
Thank you for yours hint. I use tsup
and everything seem right.
For other folks, please take a look here, you might found it's great example.
Guidance for this can be found in the latest iteration of the documentation: https://turbo.build/repo/docs/guides/tools/typescript#creating-entrypoints-to-the-package
What version of Turborepo are you using?
1.9.3
What package manager are you using / does the bug impact?
Yarn v1
What operating system are you using?
Windows
Describe the Bug
The import work, but the auto import is not working, so I should manually write the import. Here is my structure:
package.json
tsconfig.json
index.ts
apps/docs/package.json
Expected Behavior
Should auto suggested and auto import in vs code
To Reproduce
Reproduction Repo
No response