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

fix: fix dynamic require() of next #123

Merged
merged 1 commit into from
Mar 11, 2021
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
2 changes: 2 additions & 0 deletions helpers/validateNextUsage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const validateNextUsage = function (failBuild) {
)
}

// We cannot load `next` at the top-level because we validate whether the
// site is using `next` inside `onPreBuild`.
// Old Next.js versions are not supported
const { version } = require('next/package.json')
if (ltVersion(version, MIN_VERSION)) {
Expand Down
6 changes: 4 additions & 2 deletions src/lib/helpers/getSortedRedirects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { getSortedRoutes: getSortedRoutesFromNext } = require('next/dist/next-server/lib/router/utils/sorted-routes')
const removeFileExtension = require('./removeFileExtension')

// Return an array of redirects sorted in order of specificity, i.e., more generic
Expand All @@ -9,8 +8,11 @@ const getSortedRedirects = (redirects) => {
// after sorting
const routesWithoutExtensions = redirects.map(({ route }) => removeFileExtension(route))

// We cannot load `next` at the top-level because we validate whether the
// site is using `next` inside `onPreBuild`.
// Sort the "naked" routes
const sortedRoutes = getSortedRoutesFromNext(routesWithoutExtensions)
const { getSortedRoutes } = require('next/dist/next-server/lib/router/utils/sorted-routes')
const sortedRoutes = getSortedRoutes(routesWithoutExtensions)

// Return original routes in the sorted order
return redirects.sort((a, b) => {
Expand Down