Skip to content

Better specify expected Node.js version and update to v20.19.2 #399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2025

Conversation

doshitan
Copy link
Contributor

The container image was pinned to Node.js 20.18.1, see Dockerfile:

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] #392
[2] https://nodejs.org/en/blog/release/v20.19.0/#requireesm-is-now-enabled-by-default

Testing

navapbc/platform-test-nextjs#99

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] #392
[2] https://nodejs.org/en/blog/release/v20.19.0/#requireesm-is-now-enabled-by-default
@doshitan doshitan merged commit 606495c into main May 30, 2025
1 check passed
@doshitan doshitan deleted the doshitan/fix-node-version branch May 30, 2025 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant