-
Notifications
You must be signed in to change notification settings - Fork 7
Description
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:
- 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)