I have a troubleshoot with Docker and a monorepo based on PNPM Workspace + NX.
It simply doesn't compile.
I get the message :
=> ERROR [ 9/12] RUN pnpm build-schema 1.0s
------
> [ 9/12] RUN pnpm build-schema:
#0 0.495
#0 0.495 > profilart@1.0.0 build-schema /
#0 0.495 > npx nx build schemas
#0 0.495
#0 0.937
#0 0.938 > NX The current directory isn't part of an Nx workspace.
#0 0.938
#0 0.938 To create a workspace run:
#0 0.938 npx create-nx-workspace@latest <workspace name>
#0 0.938
#0 0.938 To add Nx to existing workspace run with a workspace-specific nx.json:
#0 0.938 npx add-nx-to-monorepo@latest
#0 0.938
#0 0.938 To add the default nx.json file run:
#0 0.938 nx init
#0 0.938
#0 0.938
#0 0.942 > NX For more information please visit https://nx.dev/
#0 0.942
#0 0.961 ELIFECYCLE Command failed with exit code 1.
What I don't understand is that it is already on an Nx workspace as I used the command pnpm add nx -D -w
My pnpm-workspace.yaml contains this :
# pnpm-workspace.yaml
packages:
# executable/launchable applications
- 'apps/*'
# all packages in subdirs of packages/ and components/
- 'packages/*'
My package.json:
{
"name": "xxx",
"version": "1.0.0",
"description": "",
"main": "index.ts",
"scripts": {
"start": "npx nx run-many --target=start --all ",
"dev": "npx nx run-many --target=dev --all",
"start-bo": "npx nx start xxx-bo ",
"start-bo:dev": "npx nx dev xxx-bo ",
"start-api": "npx nx start xxx-api",
"start-api:dev": "npx nx start:dev xxx-api",
"build": "npx nx run-many --target=build --all",
"build-bo": "npx nx build xxx-bo",
"build-api": "npx nx build xxx-api",
"build-schema": "npx nx build schemas"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"nx": "^15.2.4",
"concurrently": "^7.6.0"
}
}
start-bo and start-api refer to projects based in /apps folder which have their own package.json. API is based on NESTJS and BO on React + NextJS.
My dockerfile has this :
# Filename: Dockerfile
FROM node:alpine
ENV NODE_VERSION 16.17.0
RUN npm install -g pnpm
RUN npm install typescript -g
RUN apk add make gcc g++
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
ADD / /
WORKDIR /
COPY . .
RUN pnpm install --prod
RUN pnpm build-schema
RUN pnpm build-api
RUN pnpm build-bo
EXPOSE 8080
CMD ["pnpm" "start"]
It fails when I launch RUN pnpm build-schema
.
I actually use the root folder since it doesn't work in sub folders because of gcc used to compile scrypt (it's another problem I'll treat later).
Is there something I missed?
I try to run npx add-nx-to-monorepo@latest
and it just doesn't move, I forced stopping after 5 minutes, it's blocked.
Thanks for your help.