Skip to content

Commit

Permalink
[NextJs] Fix "debug module not found" error in redirects middleware (#…
Browse files Browse the repository at this point in the history
…1045)

* Remove import of next.config.js in redirects middleware (fixes #535263) and use static values for now. next.config.js is not intended to be imported in this way. We should have access to locales directly in middleware in the future: vercel/next.js#37253

* Add type assist jsdoc for NextConfig
  • Loading branch information
ambrauer authored May 30, 2022
1 parent ad76808 commit 2e28076
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const { constants } = require('@sitecore-jss/sitecore-jss-nextjs');
const disconnectedServerUrl = `http://localhost:${process.env.PROXY_PORT || 3042}/`;
const isDisconnected = process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED;

/**
* @param {import('next').NextConfig} nextConfig
*/
const disconnectedPlugin = (nextConfig = {}) => {
if (!isDisconnected) {
return nextConfig;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @param {import('next').NextConfig} nextConfig
*/
const styleguidePlugin = (nextConfig = {}) => {
return Object.assign({}, nextConfig, {
i18n: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { NextRequest, NextResponse } from 'next/server';
import { RedirectsMiddleware } from '@sitecore-jss/sitecore-jss-nextjs/edge';
import config from 'temp/config';
import { MiddlewarePlugin } from '..';
import nextConfig from '../../../../next.config';

class RedirectsPlugin implements MiddlewarePlugin {
private redirectsMiddleware: RedirectsMiddleware;
Expand All @@ -13,7 +12,9 @@ class RedirectsPlugin implements MiddlewarePlugin {
endpoint: config.graphQLEndpoint,
apiKey: config.sitecoreApiKey,
siteName: config.jssAppName,
locales: nextConfig().i18n.locales,
// These are all the locales you support in your application.
// These should match those in your next.config.js (i18n.locales).
locales: ['en'],
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @param {import('next').NextConfig} nextConfig
*/
const robotsPlugin = (nextConfig = {}) => {
return Object.assign({}, nextConfig, {
async rewrites() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @param {import('next').NextConfig} nextConfig
*/
const sitemapPlugin = (nextConfig = {}) => {
return Object.assign({}, nextConfig, {
async rewrites() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const plugins = require('./src/temp/next-config-plugins') || {};

const publicUrl = getPublicUrl();

/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
// Set assetPrefix to our public URL
assetPrefix: publicUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @param {import('next').NextConfig} nextConfig
*/
const edgePlugin = (nextConfig = {}) => {
return Object.assign({}, nextConfig, {
webpack: (config, options) => {
Expand All @@ -6,7 +9,7 @@ const edgePlugin = (nextConfig = {}) => {
// Point the Edge compiler in the right direction for 3rd-party module browser bundles.

// debug
config.resolve.alias.debug = require.resolve('debug/src/browser');
config.resolve.alias['debug'] = require.resolve('debug/src/browser');

// graphql-request
config.resolve.alias['cross-fetch'] = require.resolve('cross-fetch/dist/browser-ponyfill');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @param {import('next').NextConfig} nextConfig
*/
const graphqlPlugin = (nextConfig = {}) => {
return Object.assign({}, nextConfig, {
webpack: (config, options) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const path = require('path');

const CWD = process.cwd();

/**
* @param {import('next').NextConfig} nextConfig
*/
const monorepoPlugin = (nextConfig = {}) => {
return withTM(Object.assign({}, nextConfig, {
webpack: (config, options) => {
Expand Down

0 comments on commit 2e28076

Please sign in to comment.