Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add type="module" to package.json #225

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/fluent-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
"opentiny",
"fluent-editor"
],
"type": "module",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify the impact of enabling ES modules.

Adding "type": "module" changes how Node.js interprets .js files as ES modules by default. This could affect:

  • Existing .js files that use CommonJS syntax
  • Import/export statements throughout the codebase
  • Scripts that aren't ready for ESM

Let's verify the codebase compatibility:


🏁 Script executed:

#!/bin/bash
# Check for potential CommonJS syntax in .js files that might break
echo "Checking for require() calls in .js files..."
rg "require\(" --type js

echo "Checking for module.exports in .js files..."
rg "module\.exports" --type js

echo "Checking for __dirname/__filename usage in .js files..."
rg "__dirname|__filename" --type js

Length of output: 580


ESM Package: Potential Compatibility Issues with CommonJS Scripts

The addition of "type": "module" in package.json means that .js files are now treated as ES modules by default, which could break files still written using CommonJS syntax. We found that:

  • verifyCommit.js uses require() to import modules.
  • jest.config.js uses module.exports.

These patterns will lead to runtime issues unless those files are either renamed to use a .cjs extension (as done for the pre-release script) or are refactored to use ES module syntax.

"main": "src/index.ts",
"module": "src/index.ts",
"types": "types/index.d.ts",
"scripts": {
"start": "vite build && vite",
"dev": "vite",
"build": "pnpm build:theme && vite build && node scripts/pre-release.js",
"build": "pnpm build:theme && vite build && node scripts/pre-release.cjs",
"build:theme": "vite build --config vite.config.theme.ts",
"test": "jest"
},
Expand Down
Loading