Skip to content

Commit

Permalink
remove `Critical dependency: the request of a dependency is an expres…
Browse files Browse the repository at this point in the history
…sion` warnings (#3330)

* patch `@typescript/vfs` to remove `Critical dependency: the request of a dependency is an expression` warnings

* fix

* Update .changeset/dry-seas-pull.md

* aa

* prettier
  • Loading branch information
dimaMachina authored Oct 2, 2024
1 parent 90d7ce1 commit 82fc267
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-seas-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nextra': patch
---

remove `Critical dependency: the request of a dependency is an expression` warnings
35 changes: 20 additions & 15 deletions packages/nextra/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const DEFAULT_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx']

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

const RE_SEP = sep === '/' ? '/' : '\\\\'

const nextra: Nextra = nextraConfig => {
const { error } = nextraConfigSchema.safeParse(nextraConfig)
if (error) {
Expand Down Expand Up @@ -152,6 +154,14 @@ const nextra: Nextra = nextraConfig => {
})
}

const defaultLoaderOptions = [
options.defaultLoaders.babel,
{
loader: 'nextra/loader',
options: loaderOptions
}
]

rules.push(
{
// Match Markdown imports from non-pages. These imports have an
Expand All @@ -162,13 +172,7 @@ const nextra: Nextra = nextraConfig => {
issuer: request =>
(!!request && !request.includes(AGNOSTIC_PAGE_MAP_PATH)) ||
request === null,
use: [
options.defaultLoaders.babel,
{
loader: 'nextra/loader',
options: loaderOptions
}
]
use: defaultLoaderOptions
},
{
// Match pages (imports without an issuer request).
Expand Down Expand Up @@ -198,15 +202,16 @@ const nextra: Nextra = nextraConfig => {
},
{
// Use platform separator because /pages\/_app\./ will not work on windows
test: new RegExp(`pages${sep === '/' ? '/' : '\\\\'}_app\\.`),
test: new RegExp(`pages${RE_SEP}_app\\.`),
issuer: request => !request,
use: [
options.defaultLoaders.babel,
{
loader: 'nextra/loader',
options: loaderOptions
}
]
use: defaultLoaderOptions
},
{
test: new RegExp(
`@typescript${RE_SEP}vfs${RE_SEP}dist${RE_SEP}vfs\\.`
),
issuer: request => !!request,
use: defaultLoaderOptions
}
)

Expand Down
8 changes: 8 additions & 0 deletions packages/nextra/src/server/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ export async function loader(

const currentPath = slash(mdxPath)

if (currentPath.includes('@typescript/vfs/dist/vfs.')) {
// Fixes https://github.com/microsoft/TypeScript-Website/pull/3022
// Fixes https://github.com/shuding/nextra/issues/3322#issuecomment-2384046618
return source
.replace(/String\.fromCharCode\(112, ?97, ?116, ?104\)/, '"path"')
.replace(/String\.fromCharCode\(102, ?115\)/, '"fs"')
}

if (currentPath.includes('/pages/api/')) {
logger.warn(
`Ignoring ${currentPath} because it is located in the "pages/api" folder.`
Expand Down

0 comments on commit 82fc267

Please sign in to comment.