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 Critical dependency: the request of a dependency is an expression warnings #3330

Merged
merged 6 commits into from
Oct 2, 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/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