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

remove warning Watchpack Error (initial scan): Error: ENOTDIR: not a directory, scandir 'path-to-your-node_modules/next/dist/pages/_app.js' #3328

Merged
merged 3 commits into from
Sep 30, 2024
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
5 changes: 5 additions & 0 deletions .changeset/cyan-points-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nextra': patch
---

remove warning `Watchpack Error (initial scan): Error: ENOTDIR: not a directory, scandir 'path-to-your-node_modules/next/dist/pages/_app.js'`
27 changes: 15 additions & 12 deletions packages/nextra/src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-env node */
import { createRequire } from 'node:module'
import { sep } from 'node:path'
import { join, sep } from 'node:path'
import type { NextConfig } from 'next'
import { fromZodError } from 'zod-validation-error'
import type { Nextra } from '../types'
Expand All @@ -19,8 +18,6 @@ import { NextraPlugin, NextraSearchPlugin } from './webpack-plugins/index.js'

const DEFAULT_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx']

const require = createRequire(import.meta.url)

const AGNOSTIC_PAGE_MAP_PATH = `.next${sep}static${sep}chunks${sep}nextra-page-map`

const nextra: Nextra = nextraConfig => {
Expand Down Expand Up @@ -124,14 +121,20 @@ const nextra: Nextra = nextraConfig => {
)
}
}

const defaultESMAppPath = require.resolve('next/dist/esm/pages/_app.js')
const defaultCJSAppPath = require.resolve('next/dist/pages/_app.js')

config.resolve.alias = {
...config.resolve.alias,
// Resolves ESM _app file instead cjs, so we could import theme.config via `import` statement
[defaultCJSAppPath]: defaultESMAppPath
config.resolve.alias = { ...config.resolve.alias }
const { alias } = config.resolve

const appAlias = alias['private-next-pages/_app']
const appESM = 'next/dist/esm/pages/_app'
if (appAlias) {
alias['private-next-pages/_app'] = [
// Cut last element which points to CJS _app file
...appAlias.slice(0, -1),
// Resolves ESM _app file instead CJS, so we could import `theme.config` via `import` statement
appESM
]
} else {
alias[join(alias.next, 'dist', 'pages', '_app')] = appESM
}
const rules = config.module.rules as RuleSetRule[]

Expand Down