-
Say I have an app, and a package. How do I make it so inside the app/ imports come from a barrel file in This isn't strictly a turborepo problem, but should be very common given these monorepos are intended to contain many packages. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
The answer is project-relative imports. I should have known that. |
Beta Was this translation helpful? Give feedback.
-
Root package.json "name": "xxx",
"workspaces": [
"apps/store",
"packages/*"
], apps>store>package.json "name": "@xxx/store",
apps>store>tsconfig.json {
"extends": "../../packages/tsconfig/nextjs.json", // yea, relative paths there is still weird, but not a bad practice
"compilerOptions": {
"noEmit": true,
"baseUrl": ".",
"paths": {
"@/*": ["src/*"], // All app workspace source files
"@xxx/*": ["../../apps/*", "../../packages/*"] // all packages and apps from root
}
},
"include": [
"next-env.d.ts",
"./src/**/*", // I have source files here
"*.js", // root files like eslint config (because I use prettier with eslint)
".eslintrc.js",
"next.config.js"
],
"exclude": ["node_modules", ".next", ".turbo"]
} packages>package.json "name": "@xxx/tsconfig", packages>nextjs.json {
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Next.js",
"extends": "./base.json",
"compilerOptions": {
"jsx": "preserve",
"noEmit": true,
"target": "es5"
}
} packages>base.json {
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Default",
"compilerOptions": {
"allowJs": true,
"checkJs": false,
"composite": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"incremental": true,
"inlineSources": false,
"isolatedModules": true,
"lib": ["ES2021", "DOM", "DOM.Iterable"],
"module": "esnext",
"moduleResolution": "node",
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"typeRoots": ["node_modules/@types"]
},
"exclude": ["node_modules"]
} USAGE Inner import import { rootDomain } from '@/store/rootDomain'; Workspace import import config from '@xxx/config/tsconfig.json'; .vscode > xxx.code-workspace {
"folders": [
{
"name": "ROOT",
"path": "../"
},
{
"name": "@xxx/store",
"path": "../apps/store"
},
{
"name": "@xxx/config",
"path": "../packages/config"
},
],
"settings": {},
} |
Beta Was this translation helpful? Give feedback.
The answer is project-relative imports. I should have known that.