Encore doesnt allow imports from workspace packages in a pnpm monorepo
Hello please i tried to initiate encore on pnpm monorepo and tried to import packages from my packages folder but it gives me an error message stating module no found error until i install the packages found in the packages/* folder for example packages/database contains drizzle-orm in my package.json file. Every time i run encore it tell me install drizzle-orm in the encore api folder before it can work and run encore run
Please is there a way to bypass and stop encore for telling me to install the package before i can make api run @fredr @marcuskohlberg
Hi, could you create a git repository with a minimal reproduction so I can test it out? I have a hard time understanding your project structure, and there are so many ways of setting these things up.
Two things to consider, first make sure you are running the latest version of encore (v1.46.10) as we did some improvements for monorepos in that version. Secondly, when using pnpm, make sure that you set the packageManager field in your package.json (you can set it in the root package.json or the encore app package.json) to "pnpm@<version>" and replace <version> with whatever pnpm --version gives you.
Github encore-monorepo this is the repo, encore is in the apps/apiw folder on the process of migration from nextjs api to encore api ts runtime
the issue is noticed that encore bundles everything into a single mainjs file so if the imported file contains npm packages from external pnpm workspace packages, encore wants the npm package to be in the apiw folder so it will not run until you install it meaning if the npm packages is installed in the packages/* folder encore doesnt recongnize it @fredr
I was also having the same issues with a similar folder structure that @firstaxel mentioned.
Although this can be workaround by:
- Put all backend-related libs inside
apps/encore-backend/libs/some-backend-lib. This way pnpm/nx/(any monorepo workspace tools) still be able to recognized this as an individual lib package, just have to addapps/encore-backend/libs/*into your workspace setting - Put
encore.appat root, and define the backend code in a folder (let's sayapi), while keeping other packages in separate folder. (With this way, we need to specify multiple tsconfig files for TS to work properly). One potential drawback is that the docker image size will be big since there's no ignore config file for encore yet...
Welp eventually I hope encore can work well with all the major monorepo tools without having to worry about these kinds of directory structure...
Looking forward for the updates..
Similar issue, I have a relatively standard pnpm monorepo setup.
~/apps/* and ~/packages/*
I have my encore app stored at ~/apps/encore/* and a shared packaged at ~/packages/shared-config/*
and my package.json in my encore app @etx/shared-config": "workspace:*" but during runtime i get import errors
node:internal/modules/esm/resolve:265
throw new ERR_MODULE_NOT_FOUND
Linking to my own experience - I got Encore working with Turborepo with two simple steps:
- Build all workspace dependencies within your encore-app package
postinstallscript - Declare
packageManagerwithin your encore-app package.json as well as your root
Context https://github.com/encoredev/encore/issues/2021#issuecomment-3135686720