Skip to content

Commit 6158489

Browse files
authored
fix(next): suppress webpack "Critical dependency" warning in dynamicImport (#15534)
The Vitest-only branch in `dynamicImport` uses a bare `import(importPath)` which webpack still statically analyzes, even though it's behind a `process.env.VITEST` condition. This could cause a `"Critical dependency: the request of a dependency is an expression"` warning in Next.js projects. Adding `/* webpackIgnore: true */` should fix this. Additionally, this hides another sass deprecation warning
1 parent 8ea162c commit 6158489

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

packages/next/src/withPayload/withPayload.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,18 @@ export const withPayload = (nextConfig = {}, options = {}) => {
3535
}
3636

3737
const consoleWarn = console.warn
38-
const sassWarningText =
39-
'Future import deprecation is not yet active, so silencing it is unnecessary'
38+
39+
const sassWarningTexts = [
40+
// This warning is a lie - without silencing import deprecation warnings, sass will spam the console with deprecation warnings
41+
'Future import deprecation is not yet active, so silencing it is unnecessary',
42+
// Sometimes happens despite silenceDeprecations
43+
'The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0',
44+
]
4045
console.warn = (...args) => {
4146
if (
42-
(typeof args[1] === 'string' && args[1].includes(sassWarningText)) ||
43-
(typeof args[0] === 'string' && args[0].includes(sassWarningText))
47+
(typeof args[1] === 'string' && sassWarningTexts.some((text) => args[1].includes(text))) ||
48+
(typeof args[0] === 'string' && sassWarningTexts.some((text) => args[0].includes(text)))
4449
) {
45-
// This warning is a lie - without silencing import deprecation warnings, sass will spam the console with deprecation warnings
4650
return
4751
}
4852

packages/payload/src/utilities/dynamicImport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function dynamicImport<T = unknown>(modulePathOrSpecifier: string):
1818
// Vitest runs tests in a VM context where eval'd dynamic imports fail with
1919
// ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING. Use direct import in test environment.
2020
if (process.env.VITEST) {
21-
return await import(importPath)
21+
return await import(/* webpackIgnore: true */ importPath)
2222
}
2323

2424
// Without the eval, the Next.js bundler will throw this error when encountering the import statement:

0 commit comments

Comments
 (0)