[Bug]: Unable to run npm run build
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
- [x] I agree to follow this project's Code of Conduct
- [x] I checked the current issues for duplicate problems
Fixed by changing the following:
-
Added "type": "module", to package.json
-
Changed from
import examplesList from './examples-list.json' assert { type: 'json' };toimport 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'));`
Hello!
Yes, it is a known compatibility issue with latest node.js version. We will prepare a fix soon
Upgraded to the compatible syntax, the latest main branch commit should work. Let us know if the error persists