Skip to content

Commit

Permalink
Turbopack: Fail when module type is unhandled (#63535)
Browse files Browse the repository at this point in the history
This causes Turbopack to fail and communicate when a file with an
unhandled or unregistered extension is built.

Test Plan: `TURBOPACK=1 pnpm test-dev
test/development/basic/hmr.test.ts`


Closes PACK-2803
  • Loading branch information
wbinnssmith committed Mar 21, 2024
1 parent 8ab6261 commit aeafed9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 41 deletions.
70 changes: 35 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ swc_core = { version = "0.90.22", features = [
testing = { version = "0.35.20" }

# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240319.2" }
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240320.2" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240319.2" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240320.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240319.2" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240320.2" }

# General Deps

Expand Down
5 changes: 4 additions & 1 deletion packages/next/src/server/dev/turbopack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export function isWellKnownError(issue: Issue): boolean {
const { title } = issue
const formattedTitle = renderStyledStringToErrorAnsi(title)
// TODO: add more well known errors
if (formattedTitle.includes('Module not found')) {
if (
formattedTitle.includes('Module not found') ||
formattedTitle.includes('Unknown module type')
) {
return true
}

Expand Down
14 changes: 12 additions & 2 deletions test/development/basic/hmr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,17 @@ describe.each([[''], ['/docs']])(

expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxHeader(browser)).toMatch('Failed to compile')
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`

if (process.env.TURBOPACK) {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"./components/parse-error.xyz
Unknown module type
This module doesn't have an associated type. Use a known file extension, or register a loader for it.
Read more: https://nextjs.org/docs/app/api-reference/next-config-js/turbo#webpack-loaders"
`)
} else {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"./components/parse-error.xyz
Module parse failed: Unexpected token (3:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
Expand All @@ -891,7 +901,7 @@ describe.each([[''], ['/docs']])(
./components/parse-error.xyz
./pages/hmr/about8.js"
`)

}
await next.patchFile(aboutPage, aboutContent)

await check(
Expand Down

0 comments on commit aeafed9

Please sign in to comment.