Skip to content

Commit 82fc267

Browse files
authoredOct 2, 2024··
remove Critical dependency: the request of a dependency is an expression 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
1 parent 90d7ce1 commit 82fc267

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed
 

‎.changeset/dry-seas-pull.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'nextra': patch
3+
---
4+
5+
remove `Critical dependency: the request of a dependency is an expression` warnings

‎packages/nextra/src/server/index.ts

+20-15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const DEFAULT_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx']
2020

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

23+
const RE_SEP = sep === '/' ? '/' : '\\\\'
24+
2325
const nextra: Nextra = nextraConfig => {
2426
const { error } = nextraConfigSchema.safeParse(nextraConfig)
2527
if (error) {
@@ -152,6 +154,14 @@ const nextra: Nextra = nextraConfig => {
152154
})
153155
}
154156

157+
const defaultLoaderOptions = [
158+
options.defaultLoaders.babel,
159+
{
160+
loader: 'nextra/loader',
161+
options: loaderOptions
162+
}
163+
]
164+
155165
rules.push(
156166
{
157167
// Match Markdown imports from non-pages. These imports have an
@@ -162,13 +172,7 @@ const nextra: Nextra = nextraConfig => {
162172
issuer: request =>
163173
(!!request && !request.includes(AGNOSTIC_PAGE_MAP_PATH)) ||
164174
request === null,
165-
use: [
166-
options.defaultLoaders.babel,
167-
{
168-
loader: 'nextra/loader',
169-
options: loaderOptions
170-
}
171-
]
175+
use: defaultLoaderOptions
172176
},
173177
{
174178
// Match pages (imports without an issuer request).
@@ -198,15 +202,16 @@ const nextra: Nextra = nextraConfig => {
198202
},
199203
{
200204
// Use platform separator because /pages\/_app\./ will not work on windows
201-
test: new RegExp(`pages${sep === '/' ? '/' : '\\\\'}_app\\.`),
205+
test: new RegExp(`pages${RE_SEP}_app\\.`),
202206
issuer: request => !request,
203-
use: [
204-
options.defaultLoaders.babel,
205-
{
206-
loader: 'nextra/loader',
207-
options: loaderOptions
208-
}
209-
]
207+
use: defaultLoaderOptions
208+
},
209+
{
210+
test: new RegExp(
211+
`@typescript${RE_SEP}vfs${RE_SEP}dist${RE_SEP}vfs\\.`
212+
),
213+
issuer: request => !!request,
214+
use: defaultLoaderOptions
210215
}
211216
)
212217

‎packages/nextra/src/server/loader.ts

+8
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ export async function loader(
8383

8484
const currentPath = slash(mdxPath)
8585

86+
if (currentPath.includes('@typescript/vfs/dist/vfs.')) {
87+
// Fixes https://github.com/microsoft/TypeScript-Website/pull/3022
88+
// Fixes https://github.com/shuding/nextra/issues/3322#issuecomment-2384046618
89+
return source
90+
.replace(/String\.fromCharCode\(112, ?97, ?116, ?104\)/, '"path"')
91+
.replace(/String\.fromCharCode\(102, ?115\)/, '"fs"')
92+
}
93+
8694
if (currentPath.includes('/pages/api/')) {
8795
logger.warn(
8896
`Ignoring ${currentPath} because it is located in the "pages/api" folder.`

0 commit comments

Comments
 (0)
Please sign in to comment.