From 9b391c328fec924d738a235e425e408f3cc5b60e Mon Sep 17 00:00:00 2001 From: Lyle-Anthony Aigbedion Date: Fri, 13 Dec 2024 12:04:14 -0500 Subject: [PATCH] fix: Node 22.12 error with cjs imports --- package.json | 2 +- scripts/post-build.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 scripts/post-build.js diff --git a/package.json b/package.json index 83d505f..3583c09 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "getStaticDirs.d.ts" ], "scripts": { - "build": "node scripts/rm.js dist && tsc --outDir dist/es && babel src --out-dir dist/cjs --extensions '.ts,.tsx' && node scripts/npmPackDev.js", + "build": "node scripts/rm.js dist && tsc --outDir dist/es && babel src --out-dir dist/cjs --extensions '.ts,.tsx' && node scripts/npmPackDev.js && node scripts/post-build.js", "format": "prettier src example/src --write", "start:example": "npm run build && cd example && npm i ../storybook-addon-code-editor-0.0.0.tgz && npm run storybook:dev", "build:example": "npm run build && cd example && npm i ../storybook-addon-code-editor-0.0.0.tgz && npm run storybook:build", diff --git a/scripts/post-build.js b/scripts/post-build.js new file mode 100644 index 0000000..995cb40 --- /dev/null +++ b/scripts/post-build.js @@ -0,0 +1,10 @@ +import { writeFileSync } from 'fs'; +import { join } from 'path'; + +const cjsDir = join(process.cwd(), 'dist', 'cjs'); + +const packageJsonContent = { + type: 'commonjs', +}; + +writeFileSync(join(cjsDir, 'package.json'), JSON.stringify(packageJsonContent, null, 2));