Next.js wizard appends CommonJS code to ESM `next.config.js` files

オープン 初心者向け
#1,397 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
領域
cli

調査の方向性

Next.js 統合は src/nextjs/nextjs-wizard.ts にあります。新しい設定を作成する分岐(type: "module" を package.json ですでに確認している)と、既存の next.config.js を変更する分岐を比較することから始めてください。next.config.mjs がどのようにラップされるかを読み、プロジェクトの package.json が ESM を宣言している場合はその経路を再利用してください。ESM の next.config.js をカバーするように Next.js ウィザードのテストを追加または拡張してください。完了とは、生成されたファイルが import/export を使用し、require is not defined エラーなしで読み込まれることを意味します。

索引モデルが issue の本文から書いたものです。

説明

bug Next.js
Environment

@sentry/wizard master (b262ed0, 9.1.0 plus one commit), Next.js integration. Reproduced with the wizard's template in Node, not a full wizard run.

Steps to Reproduce
  1. Have a Next.js project with "type": "module" in package.json and an ESM next.config.js:
    export default {};
    
  2. Run npx @sentry/wizard -i nextjs.
Expected Result

The config is treated as ESM and wrapped the same way as next.config.mjs.

Actual Result

CommonJS code is appended:

export default {};

// Injected content via Sentry wizard below

const { withSentryConfig } = require("@sentry/nextjs");

module.exports = withSentryConfig(module.exports, { /* ... */ });

Loading the file fails:

ReferenceError: require is not defined in ES module scope, you can use import instead

src/nextjs/nextjs-wizard.ts treats every existing next.config.js as CommonJS. It only checks type: "module" when it creates a new config.

主要言語
TypeScript
スター
297
フォーク
88
平均マージ
5時間 29分
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

getsentry/sentry-wizard のほかの issue

getsentry/sentry-wizard の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。