From a96cd50133ca4b39d0e6e50bedee7f3d975f5331 Mon Sep 17 00:00:00 2001 From: Tanner Doshier Date: Fri, 30 May 2025 12:12:39 -0400 Subject: [PATCH] Better specify expected Node.js version and update to v20.19.2 The container image was pinned to Node.js 20.18.1, see `Dockerfile`: ``` docker FROM node:20.18.1-bullseye-slim AS base ``` But attempting to use 20.18.1 to build Storybook, you encounter an error: ``` { column: 35, file: '/home/doshitan/projects/platform-test-nextjs/app/.storybook/main.mjs', length: 11, line: 29, lineText: ' nextConfigPath: path.resolve(import.meta.dirname, "../next.config.js"),', namespace: '', suggestion: '' } "import.meta" is not available with the "cjs" output format and will be empty SB_CORE-SERVER_0007 (MainFileEvaluationError): Storybook couldn't evaluate your .storybook/main.mjs file. ``` This is due to a recent change[1] that switched to using `import.meta.dirname`, a feature of Node.js ESM loading, instead of the legacy `__dirname`. But automatic detection and loading a file as ESM is behind a feature flag until Node.js v20.19.0[2]. Thus breaking the Storybook build for the project's "official" Node 20.18.1 version and container workflow. So: - Update Node.js version to 20.19.2 - Add specific version requirement to `package.json`, which at least will display a warning to folks installing packages outside the container environment. - Use `package.json` specification to load the correct Node.js version in CI Which should help keep all the different environments in sync. And the new Node.js module behavior is the default in later versions as well, so might as well lean into it. [1] https://github.com/navapbc/template-application-nextjs/pull/392 [2] https://nodejs.org/en/blog/release/v20.19.0/#requireesm-is-now-enabled-by-default --- .../workflows/cd-{{app_name}}-storybook.yml.jinja | 2 +- .../.github/workflows/ci-{{app_name}}.yml.jinja | 14 +++++++------- template/{{app_name}}/Dockerfile | 2 +- template/{{app_name}}/package-lock.json | 2 +- template/{{app_name}}/package.json | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/template/.github/workflows/cd-{{app_name}}-storybook.yml.jinja b/template/.github/workflows/cd-{{app_name}}-storybook.yml.jinja index 2056b4b7..d998b243 100644 --- a/template/.github/workflows/cd-{{app_name}}-storybook.yml.jinja +++ b/template/.github/workflows/cd-{{app_name}}-storybook.yml.jinja @@ -42,7 +42,7 @@ jobs: - name: Setup Node uses: actions/setup-node@v4 with: - node-version: 20 + node-version-file: ./{{ app_name }}/package.json cache-dependency-path: ./{{ app_name }}/package-lock.json # or yarn.lock cache: npm # or yarn - name: Setup Pages diff --git a/template/.github/workflows/ci-{{app_name}}.yml.jinja b/template/.github/workflows/ci-{{app_name}}.yml.jinja index c4e3bc95..ee8daca3 100644 --- a/template/.github/workflows/ci-{{app_name}}.yml.jinja +++ b/template/.github/workflows/ci-{{app_name}}.yml.jinja @@ -14,7 +14,7 @@ defaults: working-directory: ./{{ app_name }} env: - NODE_VERSION: 20 + NODE_VERSION_FILE: ./{{ app_name }}/package.json LOCKFILE_PATH: ./{{ app_name }}/package-lock.json # or yarn.lock PACKAGE_MANAGER: npm # or yarn @@ -31,7 +31,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: ${{'{{'}} env.NODE_VERSION {{'}}'}} + node-version-file: ${{'{{'}} env.NODE_VERSION_FILE {{'}}'}} cache-dependency-path: ${{'{{'}} env.LOCKFILE_PATH {{'}}'}} cache: ${{'{{'}} env.PACKAGE_MANAGER {{'}}'}} - run: npm ci @@ -52,7 +52,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: ${{'{{'}} env.NODE_VERSION {{'}}'}} + node-version-file: ${{'{{'}} env.NODE_VERSION_FILE {{'}}'}} cache-dependency-path: ${{'{{'}} env.LOCKFILE_PATH {{'}}'}} cache: ${{'{{'}} env.PACKAGE_MANAGER {{'}}'}} - run: npm ci @@ -66,7 +66,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: ${{'{{'}} env.NODE_VERSION {{'}}'}} + node-version-file: ${{'{{'}} env.NODE_VERSION_FILE {{'}}'}} cache-dependency-path: ${{'{{'}} env.LOCKFILE_PATH {{'}}'}} cache: ${{'{{'}} env.PACKAGE_MANAGER {{'}}'}} - run: npm ci @@ -80,7 +80,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: ${{'{{'}} env.NODE_VERSION {{'}}'}} + node-version-file: ${{'{{'}} env.NODE_VERSION_FILE {{'}}'}} cache-dependency-path: ${{'{{'}} env.LOCKFILE_PATH {{'}}'}} cache: ${{'{{'}} env.PACKAGE_MANAGER {{'}}'}} - run: npm ci @@ -95,7 +95,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: ${{'{{'}} env.NODE_VERSION {{'}}'}} + node-version-file: ${{'{{'}} env.NODE_VERSION_FILE {{'}}'}} cache-dependency-path: ${{'{{'}} env.LOCKFILE_PATH {{'}}'}} cache: ${{'{{'}} env.PACKAGE_MANAGER {{'}}'}} @@ -123,7 +123,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: ${{'{{'}} env.NODE_VERSION {{'}}'}} + node-version-file: ${{'{{'}} env.NODE_VERSION_FILE {{'}}'}} cache-dependency-path: ${{'{{'}} env.LOCKFILE_PATH {{'}}'}} cache: ${{'{{'}} env.PACKAGE_MANAGER {{'}}'}} - run: npm ci diff --git a/template/{{app_name}}/Dockerfile b/template/{{app_name}}/Dockerfile index 568ec67b..396e9f3f 100644 --- a/template/{{app_name}}/Dockerfile +++ b/template/{{app_name}}/Dockerfile @@ -1,7 +1,7 @@ # This file is largely based on the template-application-flask Dockerfile and # Next.js Docker example: https://github.com/vercel/next.js/blob/canary/examples/with-docker-compose # ============================================================================= -FROM node:20.18.1-bullseye-slim AS base +FROM node:20.19.2-bullseye-slim AS base WORKDIR /app # Install dependencies diff --git a/template/{{app_name}}/package-lock.json b/template/{{app_name}}/package-lock.json index a1b8f506..2a0a7be1 100644 --- a/template/{{app_name}}/package-lock.json +++ b/template/{{app_name}}/package-lock.json @@ -58,7 +58,7 @@ "typescript": "^5.0.0" }, "engines": { - "node": ">=20.0.0", + "node": "20.19.2", "npm": ">=10.0.0" } }, diff --git a/template/{{app_name}}/package.json b/template/{{app_name}}/package.json index 3e66749c..8cd36405 100644 --- a/template/{{app_name}}/package.json +++ b/template/{{app_name}}/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "engines": { - "node": ">=20.0.0", + "node": "20.19.2", "npm": ">=10.0.0" }, "scripts": {