demos icon indicating copy to clipboard operation
demos copied to clipboard

[Bug]: Unable to run npm run build

Open alifung-slalom opened this issue 9 months ago • 1 comments

Browser

Chrome

Package version

v3.0.0

React version

18.2.0

Description

Following the README I tried running npm run build but I'm getting this error:

file:///Users/alison.fung/client_projects/demos/scripts/generate-html-files.js:4 import examplesList from '../examples-list.json' assert { type: 'json' }; ^^^^^^

SyntaxError: Unexpected identifier 'assert'

ERROR: "generate-html-files" exited with 1.

Code of Conduct

alifung-slalom avatar Mar 12 '25 16:03 alifung-slalom

Fixed by changing the following:

  • Added "type": "module", to package.json

  • Changed from import examplesList from './examples-list.json' assert { type: 'json' }; to import examplesList from './examples-list.json' with { type: 'json' };

  • Changed generate-html-files.js to the following:

`import fs from 'node:fs'; import path from 'node:path'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { writeFileAsync } from './utils/fsAsync.js'; import config from './config.js';

const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename);

const examplesListPath = join(__dirname, '../examples-list.json'); const examplesList = JSON.parse(fs.readFileSync(examplesListPath, 'utf8'));`

alifung-slalom avatar Mar 12 '25 16:03 alifung-slalom

Hello!

Yes, it is a known compatibility issue with latest node.js version. We will prepare a fix soon

just-boris avatar Mar 24 '25 14:03 just-boris

Upgraded to the compatible syntax, the latest main branch commit should work. Let us know if the error persists

just-boris avatar Mar 25 '25 11:03 just-boris