open-scd icon indicating copy to clipboard operation
open-scd copied to clipboard

Unable to build OpenSCD distribution

Open ocou-aprico opened this issue 10 months ago • 4 comments

Describe the bug

Unable to build the OpenSCD project. Snowpack fails to build the packages/distribution module.

Error message: Cannot find module '@openscd/open-scd/src/open-scd.js' from '/Users/xxxx/open-scd-0.37.1/packages/distribution'

To Reproduce

Steps to reproduce the behavior:

  1. Download the open-scd-0.37.1 ZIP file from Open SCD Git location.
  2. Unzip
  3. Launch command: npm run build or npm run serve
  4. Build failed with this error trace:

@openscd/[email protected] build snowpack build && workbox generateSW workbox-config.cjs && cp .nojekyll build/

[13:13:22] [snowpack] ! building files... [13:13:22] [snowpack] Build Result Error: There was a problem with a file build result. [13:13:22] [snowpack] Cannot find module '@openscd/open-scd/src/open-scd.js' from '/Users/xxx/open-scd-0.37.1/packages/distribution' [13:13:22] [snowpack] Error: Cannot find module '@openscd/open-scd/src/open-scd.js' from '/Users/xxx/open-scd-0.37.1/packages/distribution' at Function.resolveSync [as sync] (/Users/xxx/open-scd-0.37.1/node_modules/resolve/lib/sync.js:111:15) at Object.resolveEntrypoint (/Users/xxx/open-scd-0.37.1/node_modules/esinstall/lib/entrypoints.js:149:59) at PackageSourceLocal.resolvePackageImport (/Users/xxx/open-scd-0.37.1/node_modules/snowpack/lib/cjs/sources/local.js:619:40) at resolveImport (/Users/xxx/open-scd-0.37.1/node_modules/snowpack/lib/cjs/build/file-builder.js:94:48) ... npm error Lifecycle script build failed with error: npm error code 1

Expected behavior

Build should work out of the box.

Desktop (please complete the following information):

  • OS: Mac OS 14.6.1 (23G93) (Sonoma)
  • node: v22.14.0
  • npm: 10.9.2

ocou-aprico avatar Feb 26 '25 11:02 ocou-aprico

To Reproduce

Steps to reproduce the behavior:

Download the open-scd-0.37.1 ZIP file from Open SCD Git location.
Unzip
Launch command: npm run build or npm run serve
Build failed with this error trace:

Hey there, can you try again with these steps

  • npm install
  • npm run build
  • npm run start

In case you just care about the build output and not about the source, from version 0.38.1 on we are attaching the build output to the release, see https://github.com/openscd/open-scd/releases/tag/v0.38.1

clepski avatar Mar 10 '25 08:03 clepski

Thanks for your swift answer.

Even with the last release (v0.38.1), and after executing npm install, npm run build failed with the same error. The fact that Snowpack is deprecated and not more maintained (https://www.snowpack.dev) requires an older version of node. Possible replacement of Snowpack: Vite (recommandation from Snowpack site).

ocou-aprico avatar Mar 11 '25 15:03 ocou-aprico

I get the same error with node 20.19.0, npm 10.9.2 and Manjaro OS. As you proposed, replacing Snowpack with Vite as in https://github.com/openscd/open-scd/pull/1653 solved the build error.

Tamriel avatar Apr 13 '25 16:04 Tamriel

The automatic build on github uses node 18. That works on my system as well.

Tamriel avatar Apr 15 '25 09:04 Tamriel

FYI: the issue is caused by node 20.19 setting "require(esm) is now enabled by default" https://github.com/nodejs/node/releases/tag/v20.19.0

And a workaround is to disable it via NODE_OPTIONS, e.g. adjusting the build script to "build": "NODE_OPTIONS=--no-experimental-require-module npx nx run-many -t build --all"

This is just a workaround though and we intend to switch to Vite as a build tool

clepski avatar Oct 07 '25 11:10 clepski