#Cannot find package '@astrojs/internal-helpers' | GitHub Actions + Docker deployment

27 messages · Page 1 of 1 (latest)

steel barn
#

Hello, I've been deploying my docker image from my local pc, which worked fine (build process was in Dockerfile)
Now I'm trying to move on to GitHub Actions to automate the process, but it seems there's some dependency issues.

# docker-deployment.yml
# skipping uninteresting stuff...
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
      - name: Set up Node
        uses: actions/setup-node@v4
        with:
          node-version: 20
      - name: Install dependencies
        run: npm ci
      - name: Build website
        run: npm run build
      - name: Log in to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      - name: Build and publish image
        uses: docker/build-push-action@v6
        with:
          context: .
          push: true
          tags: user/app:latest
# Dockerfile
FROM node:20 AS runtime
WORKDIR /app

COPY dist .

ENV HOST=0.0.0.0
ENV PORT=4321
EXPOSE 4321

CMD ["node", "./server/entry.mjs"]
node:internal/modules/esm/resolve:854
  throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
        ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@astrojs/internal-helpers' imported from /app/server/entry.mjs
    at packageResolve (node:internal/modules/esm/resolve:854:9)
    at moduleResolve (node:internal/modules/esm/resolve:927:18)
    at defaultResolve (node:internal/modules/esm/resolve:1169:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)
    at link (node:internal/modules/esm/module_job:86:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v20.16.0
steel barn
#

^ adding the node_modules directory to the Dockerfile didn't help either

onyx glade
#

Try changing your CMD to CMD node ./dist/server/entry.mjs

steel barn
onyx glade
steel barn
#

that's fair, but unlike the example I'm building the application before packing it into the image

#

eh you know what, I'm just gonna stick exactly to the example

#

thanks for the link

onyx glade
#

Sure thing!

spice crowBOT
#
If your issue is resolved, please consider doing the following:
  • From the ellipses (3-dot menu) in the top-right corner of the post (not the first message), edit the tags to include the Solved tag.
  • From the same ellipses, select Close Post.
    Your post will still be available to search and can be re-opened simply by replying in it. Closing a post moves it down with older posts, so we can more easily focus on issues that still need to be resovled.
    Thank you for your help!
left granite
#

@onyx glade did you ever find a solution to this issue? I am running into the same thing and cannot figure out how to get around this issue for now. Any direction would be greatly appreciated.

onyx glade
#

Could you open a new support thread?

left granite
onyx glade
#

Oh. I see. I dont have a specific solution. But can take a look

left granite
#

I think I tagged the wrong person. I'm sorry!
Meant to tag @steel barn

steel barn
left granite
left granite
steel barn
steel barn
left granite
steel barn
#

Unless you put the source in the Dockerfile and build it on start up

left granite
#

I am using pnpm as my package manager, so it took slightly more config, but I figured that in a multi stage build you have to install twice. Once in a first stage to get all the linked dependencies then again in your environment stage with production flags to slim the image down with just dependencies and not dev devDependencies.

You just have to be really conscious of your setup. Thinking I should do a blog post because this was so pedantically complicated. Thanks for chatting with me to work through it! Much appreciated.

steel barn
#

Sounds complicated
I'd definitely give it a read

onyx glade
#
# Base stage with Node.js LTS
FROM node:20.17.0-alpine AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
ENV NODE_ENV=production
WORKDIR /app

# Enable corepack
RUN corepack enable

# Copy lockfile and fetch dependencies (prevents re-fetching on changes)
COPY pnpm-lock.yaml ./
RUN pnpm fetch

# Development stage
FROM base AS development
COPY apps/property-tax ./ # Copy only necessary files
RUN pnpm install --frozen-lockfile --production=false # Install dev dependencies

ENV HOST=0.0.0.0
EXPOSE 3000
CMD ["node", "./dist/server/entry.mjs"]

# Production stage
FROM base AS staging
COPY apps/property-tax ./ # Copy source files
RUN pnpm install --frozen-lockfile --prod # Install only production dependencies

ENV HOST=0.0.0.0
EXPOSE 3000
CMD ["node", "./dist/server/entry.mjs"]

# Final production stage for Azure
FROM staging AS production
ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
ENTRYPOINT ["/tini", "--"]

ENV PORT=80
EXPOSE 80
CMD ["node", "./dist/server/entry.mjs"]

I modified your DockerFile a bit. That may help reduce your total image size.