nextra: Watchpack Error (initial scan): Error: ENOTDIR: not a directory in v3

Describe the bug

Tried to use nextra 3.0.1 and got the following issue (reproduced in codesandbox).

To Reproduce

  1. Go to codesandbox.io
  2. Click on the Start Dev Server terminal
  3. See error and broken UI
Watchpack Error (initial scan): Error: ENOTDIR: not a directory, scandir '/project/sandbox/node_modules/next/dist/pages/_app.js'
 ⚠ ./node_modules/@typescript/vfs/dist/vfs.esm.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
./node_modules/@typescript/vfs/dist/vfs.esm.js
./node_modules/twoslash/dist/index.mjs
./node_modules/@shikijs/twoslash/dist/index.mjs
./node_modules/nextra/dist/server/compile.js
./node_modules/nextra/dist/client/components/playground.js
./node_modules/nextra/dist/client/components/index.js
./node_modules/nextra-theme-docs/dist/index.js

Expected behavior

No error in terminal and a working nextra site.

Additional context

Setup from the Getting Started tutorial with the following dependencies versions

{
  "next": "14.2.13",
  "nextra": "3.0.1",
  "nextra-theme-docs": "3.0.1",
  "react": "18.3.1",
  "react-dom": "18.3.1"
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 15
  • Comments: 31 (4 by maintainers)

Commits related to this issue

Most upvoted comments

@dimaMachina can confirm - that fixed it for me, thanks for such a quick turnaround!

@mnahkies thanks for the contribution, fix is coming!

@mnahkies can’t reproduce locally

  1. cloned your repo
  2. updated nextra/nextra-theme-docs to 3.0.9
  3. removed next-seo from theme.config
  4. refactored _meta.json to _meta.js
  5. didn’t receive any errors
 ✘ dmytro@192  ~/Desktop/repros/openapi-code-generator   main ±  yarn workspace @nahkies/openapi-code-generator-documentation build
yarn workspace v1.22.17
yarn run v1.22.17
$ next build
 ⚠ Specified "redirects" will not automatically work with "output: export". See more info here: https://nextjs.org/docs/messages/export-no-custom-routes
 ⚠ Specified "redirects" will not automatically work with "output: export". See more info here: https://nextjs.org/docs/messages/export-no-custom-routes
  ▲ Next.js 14.2.13

 ✓ Linting and checking validity of types    
   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Collecting page data    
 ✓ Generating static pages (15/15)
 ✓ Collecting build traces    
 ⚠ rewrites, redirects, and headers are not applied when exporting your application, detected (redirects). See more info here: https://nextjs.org/docs/messages/export-no-custom-routes
 ✓ Finalizing page optimization    

Route (pages)                                    Size     First Load JS
┌ ○ /                                            941 B           150 kB
├   /_app                                        0 B             145 kB
├ ● /_meta                                       241 B           145 kB
├ ○ /404                                         1.04 kB         150 kB
├ ○ /getting-started/quick-start                 6.25 kB         155 kB
├ ● /guides/_meta                                247 B           145 kB
├ ○ /guides/client-templates/typescript-angular  7.34 kB         157 kB
├ ○ /guides/client-templates/typescript-axios    7.48 kB         157 kB
├ ○ /guides/client-templates/typescript-fetch    7.58 kB         157 kB
├ ○ /guides/concepts/extract-inline-schemas      4.02 kB         153 kB
├ ○ /guides/server-templates/typescript-koa      8.53 kB         158 kB
├ ○ /overview/about                              3.95 kB         153 kB
├ ○ /overview/compatibility                      6.81 kB         156 kB
├ ○ /reference/architecture                      3.24 kB         152 kB
└ ○ /reference/cli-options                       5.44 kB         155 kB
+ First Load JS shared by all                    156 kB
  ├ chunks/framework-e82a91356956e6c8.js         44.8 kB
  ├ chunks/main-412a9cd0a25897ae.js              32.3 kB
  ├ chunks/pages/_app-bccdaae3d42700a4.js        65.8 kB
  ├ css/a509b722c23f67c3.css                     11.1 kB
  └ other shared chunks (total)                  1.75 kB

○  (Static)  prerendered as static content
●  (SSG)     prerendered as static HTML (uses getStaticProps)

✨  Done in 23.52s.
✨  Done in 23.80s.

same result when I am on renovate/all branch

@danielkleinstein I still have the same issue with 3.0.7, my fix for now is to use the patch command of pnpm/yarn/bun to comment the twoslash import and usage from nextra/dist/server/compile.js:

pnpm patch nextra

Comment the twoslash import and usage from dist/server/compile.js

// import { rendererRich, transformerTwoslash } from "@shikijs/twoslash";

// ...

transformers: isRemoteContent ? [] : [
 // transformerTwoslash({
 //   renderer: rendererRich(),
 //   explicitTrigger: true
 // })
],

Commit the patch

pnpm patch-commit <path>

Not ideal but I don’t need twoslash and it cannot be disabled right now.

For now I’m working with this workaround in next.config.mjs:

import nextra from "nextra";

const withNextra = nextra({
  theme: "nextra-theme-docs",
  themeConfig: "./theme.config.tsx",
});

export default withNextra({
  webpack: (config) => {
    config.module = {
      ...config.module,
      exprContextCritical: false,
    };

    return config;
  },
});

But this isn’t ideal.

I found how to fix warnings from @typescript/vfs without waiting for upstream fix 🎉

https://github.com/shuding/nextra/pull/3330

try 3.0.2 where the warning Watchpack Error (initial scan): Error: ENOTDIR: not a directory, scandir is gone and styles seems correctly applied

Same problem when I followed the steps here: https://nextra.site/docs/docs-theme/start