aiji42 / next-fortress

This is a Next.js plugin that redirects or rewrite for accesses that are not authenticated.
https://next-fortress.vercel.app
MIT License
45 stars 4 forks source link

サーバーサイド制御の設定を行うとnext.config.jsでエラーが発生する #210

Closed Apryl-ym closed 1 year ago

Apryl-ym commented 1 year ago

こんにちは。

【Next.js】アクセスコントロールパターン こちらの記事を拝見いたしまして、番外編のサーバーサイドで制御するパターンを実装したいと考えているのですが、 next.config.js内で記事と同様の設定を行うと、exportsにないimportをしているよとエラーが出るようです。

現在、こちらの方法は対応していなかったりするのでしょうか? ご確認いただけますでしょうか。

// next.config.js
const path = require('path');
const withPlugins = require('next-compose-plugins');

/** @type {import('next').NextConfig} */
const nextConfig = {
    reactStrictMode: true,
    swcMinify: true,
    sassOptions: {
        includePaths: [path.join(__dirname, 'styles')],
    },
};

const withFortress = require('next-fortress')({
    forts: [
        {
            inspectBy: 'firebase',
            mode: 'redirect',
            source: '/:path*',
            destination: '/login',
        },
    ],
    firebase: {
        clientEmail: process.env.FIREBASE_ADMIN_CLIENT_EMAIL,
        projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
        privateKey: process.env.FIREBASE_ADMIN_PRIVATE_KEY,
    },
});

module.exports = withPlugins([withFortress], {
    ...nextConfig,
});

エラー内容

error - Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in D:\path\to\node_modules\next-fortress\package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:440:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:645:7)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.mod._resolveFilename (D:\path\to\node_modules\next\dist\build\webpack\require-hook.js:27:32)
    at Function.mod._resolveFilename (D:\path\to\node_modules\next\dist\build\webpack\require-hook.js:27:32)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
aiji42 commented 1 year ago

@Apryl-ym 最新のバージョンでの設定はリポジトリのREADMEを参照してください。
Zennに書かれている内容は古いので、現行バージョンではその書き方では動きません。