Next.js Discord

Discord Forum

Turborepo - can't load other packages from other packages

Answered
Reddish carpenter ant posted this in #help-forum
Open in Discord
Reddish carpenter antOP
Hi there, I'm trying to understand how monorepos and turborepo works.

I got an issue where I can't seem to load one package, inside another one.

For example, I got this setup:
/packages
--/folder1
--/folder2
--/folder3


However, when I try to load a functoin from folder 1, to folder 2 - it doesn't work.

I'm confused as to why. I'm also using a CLI if that helps. So folder 2 is a CLI commando that calls a function from folder 1, no matter the typescript config or whatever I do it always breaks.

What is the proper way, the logic behind this?
Answered by joulev
folder1, folder2 and folder3 are separate packages.

if you want to use a folder1 function inside folder2, you need to declare folder1 as a dependency of folder2, then install dependencies, then

import whatever from "folder1"
View full answer

17 Replies

Answer
@joulev folder1, folder2 and folder3 are separate packages. if you want to use a folder1 function inside folder2, you need to declare folder1 as a dependency of folder2, then install dependencies, then ts import whatever from "folder1"
Reddish carpenter antOP
Oh wow. Guess that worked. Really appriciate it. Although the issue still thre, its probably something else - but at least that part there worked.

Quick question, if you're buildig somethng like Prisma or Drizzle - how would you go about the config; so you know the config you set "dirzzle.config.ts" how do you read those values, where would you store that and retrive that to your package etc...
My idea was to have a config package, let the user import that, then i import that config paackage in my package and do stuff - that's the idea right?
Never created a package like this
Reddish carpenter antOP
I think something else is wrong, when I do this:

import { Command } from 'commander';
import { loadUserConfig } from '@repo/config';

const runMigrationCommand = new Command('run:migration')
  .description('Run the migration')
  .action(async () => { //
    const config = await loadUserConfig(); 
    console.log('hellooo');
    console.log('Loaded config:', config);
  });

export default runMigrationCommand;

The entire command line stops working. If I comment the loadUserConfig - then everything works just fine.

Probably soemthing basic I bet

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\aurel\Desktop\WebDev\aaa\packages\config\dist\loadUserConfig' imported from C:\Users\aurel\Desktop\WebDev\aaa\packages\config\dist\index.js


Tried to debug this but not sure if I failed because of the no package or what
Feels like its some CLI stuff - where it needs to importwith .js
Yeah, so when i change the dist folder and add the ".js" it works
export { loadUserConfig } from './loadUserConfig.js';
export { defineIndexedDBConfig } from './defineConfig.js';
but when it builds without the .js it doesn't
export { loadUserConfig } from './loadUserConfig.js';
export { defineIndexedDBConfig } from './defineConfig.js';
so I had to add .js in my index file
while I use TS
do you do that too?
Feels weird
seems very error proone, ive done this beore and forgot this already
i don't do this but it depends a lot on the compiler/bundler and the configurations you make to them. i have seen other libraries doing this so it's not unheard of
Reddish carpenter antOP
Seems like I don't really have a clue about the configurations. All these years and I know little about the config xd

Thanks. Guess that's something to refactor later on I suppose, maybe.