martpie / next-transpile-modules

Next.js plugin to transpile code from node_modules. Please see: https://github.com/martpie/next-transpile-modules/issues/291
MIT License
1.13k stars 85 forks source link

Turborepo + Windows + Docker #261

Closed phoenixVS closed 1 year ago

phoenixVS commented 2 years ago

Using pnpm with turborepo running in Docker (with compose) next-transpile-module doesn't see packages/ui/

To Reproduce Run in root pnpm install docker-compose up app

Setup

Dockerfile

FROM node:14-alpine

ENV NODE_ENV development

RUN npm install -g pnpm
RUN apk add git

WORKDIR /app

COPY  ["pnpm-lock.yaml", "pnpm-workspace.yaml", "package.json", "./"]

RUN --mount=type=cache,id=pnpm-store,target=/root/.pnpm-store\
      pnpm fetch

COPY . ./

RUN --mount=type=cache,id=pnpm-store,target=/root/.pnpm-store\
     pnpm -r install --frozen-lockfile --offline

EXPOSE 3000 3001 1337

CMD ["pnpm", "run", "dev"]

next.config.js

const withTM = require("next-transpile-modules")(["ui"]);
module.exports = withTM({ reactStrictMode: true });

apps/landing/package.json

{
  "name": "landing",
  "version": "0.1.1",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "next": "12.0.8",
    "next-compose-plugins": "^2.2.1",
    "next-pwa": "^5.5.2",
    "next-transpile-modules": "9",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "ui": "workspace:*"
  },
  "devDependencies": {
    "@babel/core": "^7.17.10",
    "@types/node": "^17.0.12",
    "@types/react": "17.0.37",
    "config": "workspace:*",
    "eslint": "7.32.0",
    "tsconfig": "workspace:*",
    "typescript": "^4.5.3",
    "webpack": "^5.72.0"
  },
  "peerDependencies": {
    "@babel/core": "^7.17.10",
    "webpack": "^5.72.0"
  }
}

packages/ui/package.json

{
  "name": "ui",
  "version": "0.0.0",
  "main": "./index.tsx",
  "types": "./index.tsx",
  "license": "MIT",
  "devDependencies": {
    "@types/react": "^17.0.37",
    "@types/react-dom": "^17.0.11",
    "tsconfig": "workspace:*",
    "config": "workspace:*",
    "typescript": "^4.5.3"
  }
}

Screenshot 2022-05-10 161549

martpie commented 2 years ago

So let's isolate things here. First, does it work without Docker on a local setup?

phoenixVS commented 2 years ago

pnpm run build pnpm run dev Both works correct Only errored in docker-compose up app

phoenixVS commented 2 years ago

Maybe problem is relative with using docker volumes for node_modules

Here is docker-compose.yml

version: '3.9'

services:

  app: &app
    container_name: gxpaas
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "3000:3000"
      - "3001:3001"
      - "1337:1337"
    volumes:
      - .:/app
      - /app/node_modules

  db:
   image: cockroachdb/cockroach:v19.2.2
   ports:
     - "26257:26257"
     - "8080:8080"
   command: start-single-node --insecure
   volumes:
     - "./cockroach-data/crdb:/cockroach/cockroach-data"

networks:
  turbo-network:
    driver: bridge