Fix build/start commands for Atomic projects on Node < 20.19.0
CLI-generated Atomic projects fail to build or start on Node < 20.19.0 due to ES module handling differences when Stencil internally converts ES imports to CommonJS require() calls for the @coveo/create-atomic-rollup-plugin package.
Changes
Detection and patching logic (createAtomicProject.ts):
- Added
shouldAddExperimentalDetectModuleFlag()to detect Node < 20.19.0 using semver - Added
patchPackageJsonScripts()to inject--experimental-detect-moduleflag into generated project'sbuildandstartscripts - Modified
createAtomicApp()to apply patch after successful project creation
Pattern matching:
- Only patches scripts starting with
stencilcommand (regex:^\s*stencil\b) - Replaces
stencil→node --experimental-detect-module ./node_modules/.bin/stencil
Error handling:
- Logs warning with project path and manual fix instructions if patching fails
- Does not fail project creation on patch errors
Example
Before (generated project fails on Node 20.18.0):
{
"scripts": {
"start": "stencil build --dev --watch --serve",
"build": "stencil build && node deployment.esbuild.mjs"
}
}
After (auto-patched on Node < 20.19.0):
{
"scripts": {
"start": "node --experimental-detect-module ./node_modules/.bin/stencil build --dev --watch --serve",
"build": "node --experimental-detect-module ./node_modules/.bin/stencil build && node deployment.esbuild.mjs"
}
}
[!WARNING]
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/1108766/chrome-linux.zip
- Triggering command:
node install.js(http block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to the custom allowlist in this repository's Copilot coding agent settings (admins only)
Original prompt
This section details on the original issue you should resolve
<issue_title>build/start commands fail in CLI-generated Atomic projects when using Node < 20.19.0</issue_title> <issue_description>## Describe the bug
When executing the
buildorstartcommand in an Atomic project generated with the CLI, the command fails with an ES module error.To Reproduce
Steps to reproduce the behavior:
- nvm install 20.18
- nvm use 20.18
- npm i -g @coveo/cli@latest
- coveo auth:login -o=orgid
- coveo ui:create:atomic --version=latest my-project
- In the generated project, edit /src/index.ts to remove HTMLAtomicSearchInterfaceElement (this is another, unrelated issue).
- npm run build (should fail with an ES module error).
- npm run start (should fail with an ES module error).
Note: If you run the reproduction steps by using 20.19 instead of 20.18 at steps 1 and 2, steps 7 and 8 will not fail.
Expected behavior
The npm run build and npm run start commands should succeed without any errors or warnings on node 20.x, not just node >= 20.19
Desktop (please complete the following information):
- OS: macOS
- OS version: Sequoia 15.16.1
- Browser: N/A
- Browser version: N/A
- Version of the CLI: 3.2.13
- Local Node version: 20.18
- Local NPM version: 10.8.2
Additional context
Cause
The apparent root cause is that the @coveo/create-atomic-rollup-plugin package is distributed as a pure ES module (with "type": "module" in its package.json), but the Stencil configuration is trying to import it using the old CommonJS require import syntax.
The stencil.config.ts file uses the correct “import” syntax, but at build time, the Stencil compiler internally converts the ES module imports to require() calls.
Node.js versions < 20.19 have stricter ES module handling, which causes the build to fail when using node 20.9.0 and 20.17.0, but not when using 20.19.0.
Workarounds
Option 1: Use node >= 20.19 (however you must use node 20, as the CLI doesn’t currently support node > 20).
Option 2: Replace the build and start scripts in the CLI-generated project’s package.json as follows:
{ // ... "scripts": { "start": "node --experimental-detect-module ./node_modules/.bin/stencil build --dev --watch --serve", "build": "node --experimental-detect-module ./node_modules/.bin/stencil build && node deployment.esbuild.mjs", // ... } // ... }Potential Fix
We’d have to make sure that when we generate an Atomic project with the CLI, if the node version is below 20.19, we pass the --experimental-dectect-module flag when running the Stencil buildcommand in the project’s package.json build and start commands.
Reference
- The discuss thread that identified the issue: https://discuss.coveo.com/t/support-00130241-creating-an-atomic-page-with-the-cli-requires-adding-skiplibcheck-true-in-compileroptions-of-the-tsconfig-json/13833
- Node 20.19.0 release notes: Node.js — Node.js v20.19.0 (LTS)</issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes coveo/cli#1519
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Pull Request Title is not semantic:
:pencil2: input: [WIP] Fix build and start command errors in Atomic projects :x: subject may not be empty [subject-empty] :x: type may not be empty [type-empty]
:x: found 2 problems, 0 warnings :information_source: Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
Pull Request Title is not semantic:
:pencil2: input: Fix build/start commands for Atomic projects on Node < 20.19.0 :x: subject may not be empty [subject-empty] :x: type may not be empty [type-empty]
:x: found 2 problems, 0 warnings :information_source: Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint