Skip to content

build/start commands fail in CLI-generated Atomic projects when using Node < 20.19.0 #1519

@fbeaudoincoveo

Description

@fbeaudoincoveo

Describe the bug

When executing the build or start command in an Atomic project generated with the CLI, the command fails with an ES module error.

To Reproduce

Steps to reproduce the behavior:

  1. nvm install 20.18
  2. nvm use 20.18
  3. npm i -g @coveo/cli@latest
  4. coveo auth:login -o=orgid
  5. coveo ui:create:atomic --version=latest my-project
  6. In the generated project, edit /src/index.ts to remove HTMLAtomicSearchInterfaceElement (this is another, unrelated issue).
  7. npm run build (should fail with an ES module error).
  8. 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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions