Skip to content

Conversation

@azu
Copy link
Collaborator

@azu azu commented Aug 11, 2025

Summary

  • Node.js 24でテストが失敗する問題を修正
  • 不要なBabel関連の依存を削除

変更内容

  • .mocharc.jsonから@babel/registerの設定を削除
  • package.jsonから以下のBabel関連パッケージを削除:
    • @babel/core
    • @babel/preset-env
    • @babel/register

背景

プロジェクトは既にES module形式("type": "module")に移行済みのため、Babelによるトランスパイルは不要です。

Node.js 24では、ES moduleプロジェクトでCommonJS形式のrequireを使用すると、より厳格なエラーチェックが行われるようになりました。.mocharc.json@babel/registerをrequireしていたことが原因でテストが失敗していました。

テスト結果

ローカル環境(Node.js 24.5.0)でテストを実行し、すべてのテストがパスすることを確認しました。

ℹ tests 1041 ℹ suites 75 ℹ pass 1041 ℹ fail 0 

🤖 Generated with Claude Code

@bot-user
Copy link

bot-user commented Aug 11, 2025

Deploy Preview for js-primer ready!

Name Link
🔨 Latest commit 5ec09f3
🔍 Latest deploy log https://app.netlify.com/projects/js-primer/deploys/6899b1e3300f570008fde41f
😎 Deploy Preview https://deploy-preview-1832--js-primer.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Node.js 24でテストが失敗する問題を修正するため、不要なBabel関連の依存を削除しました。 - .mocharc.jsonから@babel/registerの設定を削除 - package.jsonから@babel/core, @babel/preset-env, @babel/registerを削除 プロジェクトは既にES module形式("type": "module")に移行済みのため、 Babelによるトランスパイルは不要です。 これによりNode.js 24でのテスト実行時に発生していたCommonJSとES moduleの 混在エラーが解消されます。 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
@azu azu force-pushed the fix/remove-babel-for-node24 branch from ff8c81b to 5ec09f3 Compare August 11, 2025 09:03
@azu azu marked this pull request as ready for review August 11, 2025 09:04
@azu azu merged commit dec1611 into master Aug 11, 2025
19 checks passed
@azu azu deleted the fix/remove-babel-for-node24 branch August 11, 2025 09:05
@azu
Copy link
Collaborator Author

azu commented Aug 11, 2025

 [test:basic ] Exception during run: ReferenceError: require is not defined in ES module scope, you can use import instead [test:basic ] This file is being treated as an ES module because it has a '.js' file extension and '/home/runner/work/js-primer/js-primer/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. [test:basic ] at file:///home/runner/work/js-primer/js-primer/source/basic/condition/test/if/leap-year-flat-example-test.js:3:15 [test:basic ] at ModuleJobSync.runSync (node:internal/modules/esm/module_job:507:37) [test:basic ] at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:441:47) [test:basic ] at loadESMFromCJS (node:internal/modules/cjs/loader:1567:24) [test:basic ] at Module._compile (node:internal/modules/cjs/loader:1720:5) [test:basic ] at Module._compile (/home/runner/work/js-primer/js-primer/node_modules/pirates/lib/index.js:117:24) [test:basic ] at node:internal/modules/cjs/loader:1871:10 [test:basic ] at Object.newLoader [as .js] (/home/runner/work/js-primer/js-primer/node_modules/pirates/lib/index.js:121:7) [test:basic ] at Module.load (node:internal/modules/cjs/loader:1470:32) [test:basic ] at Module._load (node:internal/modules/cjs/loader:1290:12) [test:basic ] at TracingChannel.traceSync (node:diagnostics_channel:322:14) [test:basic ] at wrapModuleLoad (node:internal/modules/cjs/loader:238:24) [test:basic ] at Module.require (node:internal/modules/cjs/loader:1493:12) [test:basic ] at require (node:internal/modules/helpers:152:16) [test:basic ] at Object.requireModule [as requireOrImport] (/home/runner/work/js-primer/js-primer/node_modules/mocha/lib/nodejs/esm-utils.js:94:12) [test:basic ] at Object.exports.loadFilesAsync (/home/runner/work/js-primer/js-primer/node_modules/mocha/lib/nodejs/esm-utils.js:123:34) [test:basic ] at Mocha.loadFilesAsync (/home/runner/work/js-primer/js-primer/node_modules/mocha/lib/mocha.js:451:19) [test:basic ] at singleRun (/home/runner/work/js-primer/js-primer/node_modules/mocha/lib/cli/run-helpers.js:164:15) [test:basic ] at exports.runMocha (/home/runner/work/js-primer/js-primer/node_modules/mocha/lib/cli/run-helpers.js:241:10) [test:basic ] at Object.exports.handler (/home/runner/work/js-primer/js-primer/node_modules/mocha/lib/cli/run.js:379:11) [test:basic ] at /home/runner/work/js-primer/js-primer/node_modules/mocha/node_modules/yargs/build/index.cjs:1:8993 [test:basic ] at /home/runner/work/js-primer/js-primer/node_modules/mocha/node_modules/yargs/build/index.cjs:1:4949 [test:nodecli ] 

この変更で修正された。
なぜかnode 24だけで起きた

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants