Skip to content

Commit

Permalink
remove warning `Watchpack Error (initial scan): Error: ENOTDIR: not a…
Browse files Browse the repository at this point in the history
… directory, scandir 'path-to-your-node_modules/next/dist/pages/_app.js'` (#3328)

* aa

* aa

* fix
  • Loading branch information
dimaMachina authored Sep 30, 2024
1 parent 991b69a commit b6341f7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
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

0 comments on commit b6341f7

Please sign in to comment.