Skip to content

Turbopack: report unknown module types at the import - #100534

Draft
lukesandberg wants to merge 1 commit into
require_context_virtual_sourcefrom
unknown_module_type_import_location
Draft

lukesandberg wants to merge 1 commit into
require_context_virtual_sourcefrom
unknown_module_type_import_location

Conversation

@lukesandberg

@lukesandberg lukesandberg commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A file that no module type applies to (e.g. a .txt without a loader) never becomes a module, so it has no place in the module graph. Its "Unknown module type" error had no location and no import trace, and did not say which import pulled the file in. This was worst for requests the user did not write by hand, like dynamic require(./dir/${x}) requests, globs and contexts.

handle_resolve_error now records the location of the import on such files in the resolve result. When a file turns out to be needed as a module, it is reported at that import, naming the file. Files that are only resolved and never needed as modules (e.g. traced externals like sharp's require.resolve of a .dylib) are still not reported, as before. Files resolved without a known import location are reported without one, as before.

This also replaces the custom "import.meta.glob() matched a file that has no module type" issue, since the general one now points at the call.

Stacked on #100526.

Verification

  • New execution tests unknown-module-type and require-context-unknown-type; updated issue snapshots for dynamic-unrelated and import-meta-glob-unknown-type.
  • test/production/app-dir/import-meta-glob-unknown-type (the code frame is syntax highlighted, so the test now strips ANSI codes).
  • test/e2e/app-dir/next-image (start, Turbopack): no new errors for traced files.

@lukesandberg
lukesandberg added this pull request to stack #100536 October 21, 2026 18:46
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Failing test suites

Commit: 3f8a865 | About building and testing Next.js

pnpm test-dev-experimental-turbo test/e2e/transpile-packages-typescript-foreign/index.test.ts (turbopack) (Experimental) (job)

  • transpile-packages-typescript-foreign > without transpilePackages > should fail (DD)
Expand output

● transpile-packages-typescript-foreign › without transpilePackages › should fail

expect(received).toContain(expected) // indexOf

Expected substring: "pkg/index.ts
Error: Unknown module type
This module doesn't have an associated type"
Received string:    "▲ Next.js 16.5.0-canary.22 (Turbopack)
- Local:         http://localhost:36945
- Network:       http://10.0.0.164:36945
✓ Ready in 355ms
⚠ `cacheComponents` is enabled without a corresponding `partialPrefetching` option. Set `partialPrefetching` to either `true` or `false`.·
The only reason to set `partialPrefetching` to `false` is if you're migrating an older Cache Components app. The initial release of Cache Components did not include Partial Prefetching. New projects should enable both Cache Components and Partial Prefetching.·
Both Cache Components and Partial Prefetching will be enabled everywhere in the next major release, and the old configurations will be removed.·
Learn more: https://nextjs.org/docs/app/guides/adopting-partial-prefetching
✓ Running next.config took 18ms
Creating turbopack project {
  dir: '/tmp/next-install-571c94c1855ea4a943aace27b5593a80df65afc6095ee0eb1603befd04e0f81d',
  testMode: true
}
- Cache Components enabled
- Experiments (use with caution):
  ✓ cachedNavigations (enabled by `__NEXT_EXPERIMENTAL_CACHED_NAVIGATIONS`)
  ✓ serverComponentsHmrCancellation (enabled by `__NEXT_EXPERIMENTAL_SERVER_COMPONENTS_HMR_CANCELLATION`)·
⨯ ./app/page.js:1:1
Error: Unknown module type
> 1 | import { Foo } from 'pkg/index.ts'
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2 |
  3 | export default function Page() {
  4 |   return <main>Hello {Foo}</main>·
node_modules/.pnpm/pkg@file+pkg/node_modules/pkg/index.ts doesn't have an associated module type. Use a known file extension, or register a loader for it.·
Read more: https://nextjs.org/docs/app/api-reference/config/next-config-js/turbopack#configuring-webpack-loaders··
React encountered an empty buffer when writing in an environment that does not support ArrayBuffer.prototype.detached. This could be a security issue if the buffer was not actually empty. Please use a modern Edge runtime that supports ArrayBuffer.prototype.detached.
 GET / 500 in 955ms (next.js: 858ms, application-code: 97ms)
"

  29 |
  30 |       if (process.env.IS_TURBOPACK_TEST) {
> 31 |         expect(next.cliOutput).toContain(`pkg/index.ts
     |                                ^
  32 | Error: Unknown module type
  33 | This module doesn't have an associated type`)
  34 |         expect(

  at Object.toContain (e2e/transpile-packages-typescript-foreign/index.test.ts:31:32)

pnpm test-start-experimental-turbo test/e2e/transpile-packages-typescript-foreign/index.test.ts (turbopack) (Experimental) (job)

  • transpile-packages-typescript-foreign > without transpilePackages > should fail (DD)
Expand output

● transpile-packages-typescript-foreign › without transpilePackages › should fail

expect(received).toContain(expected) // indexOf

Expected substring: "pkg/index.ts
Error: Unknown module type
This module doesn't have an associated type"
Received string:    "▲ Next.js 16.5.0-canary.22 (Turbopack)
⚠ `cacheComponents` is enabled without a corresponding `partialPrefetching` option. Set `partialPrefetching` to either `true` or `false`.·
The only reason to set `partialPrefetching` to `false` is if you're migrating an older Cache Components app. The initial release of Cache Components did not include Partial Prefetching. New projects should enable both Cache Components and Partial Prefetching.·
Both Cache Components and Partial Prefetching will be enabled everywhere in the next major release, and the old configurations will be removed.·
Learn more: https://nextjs.org/docs/app/guides/adopting-partial-prefetching
✓ Running next.config took 26ms
- Cache Components enabled
- Experiments (use with caution):
  ✓ cachedNavigations (enabled by `__NEXT_EXPERIMENTAL_CACHED_NAVIGATIONS`)
  ✓ serverComponentsHmrCancellation (enabled by `__NEXT_EXPERIMENTAL_SERVER_COMPONENTS_HMR_CANCELLATION`)·
  Creating an optimized production build ...·
> Build error occurred
Error: Turbopack build failed with 1 error:
./app/page.js:1:1
Error: Unknown module type
> 1 | import { Foo } from 'pkg/index.ts'
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2 |
  3 | export default function Page() {
  4 |   return <main>Hello {Foo}</main>·
node_modules/.pnpm/pkg@file+pkg/node_modules/pkg/index.ts doesn't have an associated module type. Use a known file extension, or register a loader for it.·
Read more: https://nextjs.org/docs/app/api-reference/config/next-config-js/turbopack#configuring-webpack-loaders··
    at ignore-listed frames
"

  29 |
  30 |       if (process.env.IS_TURBOPACK_TEST) {
> 31 |         expect(next.cliOutput).toContain(`pkg/index.ts
     |                                ^
  32 | Error: Unknown module type
  33 | This module doesn't have an associated type`)
  34 |         expect(

  at Object.toContain (e2e/transpile-packages-typescript-foreign/index.test.ts:31:32)

pnpm test-dev-turbo test/development/basic/hmr/error-recovery-yes-base-path-yes-asset-prefix.test.ts (turbopack) (job)

  • HMR - Error Recovery, nextConfig: {"basePath":"/docs","assetPrefix":"/asset-prefix"} > should recover after webpack parse error in an imported file (DD)
Expand output

● HMR - Error Recovery, nextConfig: {"basePath":"/docs","assetPrefix":"/asset-prefix"} › should recover after webpack parse error in an imported file

expect(received).toMatchInlineSnapshot(snapshot)

Snapshot name: `HMR - Error Recovery, nextConfig: {"basePath":"/docs","assetPrefix":"/asset-prefix"} should recover after webpack parse error in an imported file 1`

- Snapshot  - 3
+ Received  + 9

- "./components/parse-error.xyz
- Error: Unknown module type
- This module doesn't have an associated type. Use a known file extension, or register a loader for it.
+ "./pages/hmr/about8.js (1:1)
+ Error: Unknown module type
+ > 1 | import "../../components/parse-error.xyz"
+     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   2 | export default function Page() {
+   3 |   return (
+   4 |     <div className="hmr-about-page">
+
+ components/parse-error.xyz doesn't have an associated module type. Use a known file extension, or register a loader for it.

  Read more: https://nextjs.org/docs/app/api-reference/config/next-config-js/turbopack#configuring-webpack-loaders"

  433 |
  434 |         if (process.env.IS_TURBOPACK_TEST) {
> 435 |           expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
      |                                                  ^
  436 |               "./components/parse-error.xyz
  437 |               Error: Unknown module type
  438 |               This module doesn't have an associated type. Use a known file extension, or register a loader for it.

  at toMatchInlineSnapshot (development/basic/hmr/run-error-recovery-hmr-test.util.ts:435:50)
  at NextDevInstance.patchFile (lib/next-modes/base.ts:1149:9)
  at NextDevInstance.patchFile (lib/next-modes/next-dev.ts:292:16)
  at Object.<anonymous> (development/basic/hmr/run-error-recovery-hmr-test.util.ts:423:5)

pnpm test-dev-turbo test/development/basic/hmr/error-recovery-yes-base-path-no-asset-prefix.test.ts (turbopack) (job)

  • HMR - Error Recovery, nextConfig: {"basePath":"/docs","assetPrefix":""} > should recover after webpack parse error in an imported file (DD)
Expand output

● HMR - Error Recovery, nextConfig: {"basePath":"/docs","assetPrefix":""} › should recover after webpack parse error in an imported file

expect(received).toMatchInlineSnapshot(snapshot)

Snapshot name: `HMR - Error Recovery, nextConfig: {"basePath":"/docs","assetPrefix":""} should recover after webpack parse error in an imported file 1`

- Snapshot  - 3
+ Received  + 9

- "./components/parse-error.xyz
- Error: Unknown module type
- This module doesn't have an associated type. Use a known file extension, or register a loader for it.
+ "./pages/hmr/about8.js (1:1)
+ Error: Unknown module type
+ > 1 | import "../../components/parse-error.xyz"
+     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   2 | export default function Page() {
+   3 |   return (
+   4 |     <div className="hmr-about-page">
+
+ components/parse-error.xyz doesn't have an associated module type. Use a known file extension, or register a loader for it.

  Read more: https://nextjs.org/docs/app/api-reference/config/next-config-js/turbopack#configuring-webpack-loaders"

  433 |
  434 |         if (process.env.IS_TURBOPACK_TEST) {
> 435 |           expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
      |                                                  ^
  436 |               "./components/parse-error.xyz
  437 |               Error: Unknown module type
  438 |               This module doesn't have an associated type. Use a known file extension, or register a loader for it.

  at toMatchInlineSnapshot (development/basic/hmr/run-error-recovery-hmr-test.util.ts:435:50)
  at NextDevInstance.patchFile (lib/next-modes/base.ts:1149:9)
  at NextDevInstance.patchFile (lib/next-modes/next-dev.ts:292:16)
  at Object.<anonymous> (development/basic/hmr/run-error-recovery-hmr-test.util.ts:423:5)

pnpm test-dev-turbo test/development/basic/hmr/error-recovery-no-base-path-no-asset-prefix.test.ts (turbopack) (job)

  • HMR - Error Recovery, nextConfig: {"basePath":"","assetPrefix":""} > should recover after webpack parse error in an imported file (DD)
Expand output

● HMR - Error Recovery, nextConfig: {"basePath":"","assetPrefix":""} › should recover after webpack parse error in an imported file

expect(received).toMatchInlineSnapshot(snapshot)

Snapshot name: `HMR - Error Recovery, nextConfig: {"basePath":"","assetPrefix":""} should recover after webpack parse error in an imported file 1`

- Snapshot  - 3
+ Received  + 9

- "./components/parse-error.xyz
- Error: Unknown module type
- This module doesn't have an associated type. Use a known file extension, or register a loader for it.
+ "./pages/hmr/about8.js (1:1)
+ Error: Unknown module type
+ > 1 | import "../../components/parse-error.xyz"
+     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   2 | export default function Page() {
+   3 |   return (
+   4 |     <div className="hmr-about-page">
+
+ components/parse-error.xyz doesn't have an associated module type. Use a known file extension, or register a loader for it.

  Read more: https://nextjs.org/docs/app/api-reference/config/next-config-js/turbopack#configuring-webpack-loaders"

  433 |
  434 |         if (process.env.IS_TURBOPACK_TEST) {
> 435 |           expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
      |                                                  ^
  436 |               "./components/parse-error.xyz
  437 |               Error: Unknown module type
  438 |               This module doesn't have an associated type. Use a known file extension, or register a loader for it.

  at toMatchInlineSnapshot (development/basic/hmr/run-error-recovery-hmr-test.util.ts:435:50)
  at NextDevInstance.patchFile (lib/next-modes/base.ts:1149:9)
  at NextDevInstance.patchFile (lib/next-modes/next-dev.ts:292:16)
  at Object.<anonymous> (development/basic/hmr/run-error-recovery-hmr-test.util.ts:423:5)

pnpm test-dev-turbo test/development/basic/hmr/error-recovery-no-base-path-yes-asset-prefix.test.ts (turbopack) (job)

  • HMR - Error Recovery, nextConfig: {"basePath":"","assetPrefix":"/asset-prefix"} > should recover after webpack parse error in an imported file (DD)
Expand output

● HMR - Error Recovery, nextConfig: {"basePath":"","assetPrefix":"/asset-prefix"} › should recover after webpack parse error in an imported file

expect(received).toMatchInlineSnapshot(snapshot)

Snapshot name: `HMR - Error Recovery, nextConfig: {"basePath":"","assetPrefix":"/asset-prefix"} should recover after webpack parse error in an imported file 1`

- Snapshot  - 3
+ Received  + 9

- "./components/parse-error.xyz
- Error: Unknown module type
- This module doesn't have an associated type. Use a known file extension, or register a loader for it.
+ "./pages/hmr/about8.js (1:1)
+ Error: Unknown module type
+ > 1 | import "../../components/parse-error.xyz"
+     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   2 | export default function Page() {
+   3 |   return (
+   4 |     <div className="hmr-about-page">
+
+ components/parse-error.xyz doesn't have an associated module type. Use a known file extension, or register a loader for it.

  Read more: https://nextjs.org/docs/app/api-reference/config/next-config-js/turbopack#configuring-webpack-loaders"

  433 |
  434 |         if (process.env.IS_TURBOPACK_TEST) {
> 435 |           expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
      |                                                  ^
  436 |               "./components/parse-error.xyz
  437 |               Error: Unknown module type
  438 |               This module doesn't have an associated type. Use a known file extension, or register a loader for it.

  at toMatchInlineSnapshot (development/basic/hmr/run-error-recovery-hmr-test.util.ts:435:50)
  at NextDevInstance.patchFile (lib/next-modes/base.ts:1149:9)
  at NextDevInstance.patchFile (lib/next-modes/next-dev.ts:292:16)
  at Object.<anonymous> (development/basic/hmr/run-error-recovery-hmr-test.util.ts:423:5)

pnpm test-dev-turbo test/e2e/transpile-packages-typescript-foreign/index.test.ts (turbopack) (job)

  • transpile-packages-typescript-foreign > without transpilePackages > should fail (DD)
Expand output

● transpile-packages-typescript-foreign › without transpilePackages › should fail

expect(received).toContain(expected) // indexOf

Expected substring: "pkg/index.ts
Error: Unknown module type
This module doesn't have an associated type"
Received string:    "▲ Next.js 16.5.0-canary.22 (Turbopack)
- Local:         http://localhost:33673
- Network:       http://10.0.0.112:33673
✓ Ready in 345ms
✓ Running next.config took 11ms
Creating turbopack project {
  dir: '/tmp/next-install-01e23e6b28ba48f15e9834c4620af398b46bfb6a00d0962bf7996717e05753d4',
  testMode: true
}
- Experiments (use with caution):
  ✓ strictRouteTypes (enabled by `__NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES`)·
⨯ ./app/page.js:1:1
Error: Unknown module type
> 1 | import { Foo } from 'pkg/index.ts'
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2 |
  3 | export default function Page() {
  4 |   return <main>Hello {Foo}</main>·
node_modules/.pnpm/pkg@file+pkg/node_modules/pkg/index.ts doesn't have an associated module type. Use a known file extension, or register a loader for it.·
Read more: https://nextjs.org/docs/app/api-reference/config/next-config-js/turbopack#configuring-webpack-loaders··
React encountered an empty buffer when writing in an environment that does not support ArrayBuffer.prototype.detached. This could be a security issue if the buffer was not actually empty. Please use a modern Edge runtime that supports ArrayBuffer.prototype.detached.
 GET / 500 in 961ms (next.js: 861ms, application-code: 101ms)
"

  29 |
  30 |       if (process.env.IS_TURBOPACK_TEST) {
> 31 |         expect(next.cliOutput).toContain(`pkg/index.ts
     |                                ^
  32 | Error: Unknown module type
  33 | This module doesn't have an associated type`)
  34 |         expect(

  at Object.toContain (e2e/transpile-packages-typescript-foreign/index.test.ts:31:32)

pnpm test-start-turbo test/e2e/transpile-packages-typescript-foreign/index.test.ts (turbopack) (job)

  • transpile-packages-typescript-foreign > without transpilePackages > should fail (DD)
Expand output

● transpile-packages-typescript-foreign › without transpilePackages › should fail

expect(received).toContain(expected) // indexOf

Expected substring: "pkg/index.ts
Error: Unknown module type
This module doesn't have an associated type"
Received string:    "▲ Next.js 16.5.0-canary.22 (Turbopack)
✓ Running next.config took 15ms
- Experiments (use with caution):
  ✓ strictRouteTypes (enabled by `__NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES`)·
  Creating an optimized production build ...·
> Build error occurred
Error: Turbopack build failed with 1 error:
./app/page.js:1:1
Error: Unknown module type
> 1 | import { Foo } from 'pkg/index.ts'
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2 |
  3 | export default function Page() {
  4 |   return <main>Hello {Foo}</main>·
node_modules/.pnpm/pkg@file+pkg/node_modules/pkg/index.ts doesn't have an associated module type. Use a known file extension, or register a loader for it.·
Read more: https://nextjs.org/docs/app/api-reference/config/next-config-js/turbopack#configuring-webpack-loaders··
    at ignore-listed frames
"

  29 |
  30 |       if (process.env.IS_TURBOPACK_TEST) {
> 31 |         expect(next.cliOutput).toContain(`pkg/index.ts
     |                                ^
  32 | Error: Unknown module type
  33 | This module doesn't have an associated type`)
  34 |         expect(

  at Object.toContain (e2e/transpile-packages-typescript-foreign/index.test.ts:31:32)

@github-actions github-actions Bot added created-by: Turbopack team PRs by the Turbopack team. tests Turbopack Related to Turbopack with Next.js. labels Oct 21, 2026
@lukesandberg
lukesandberg force-pushed the unknown_module_type_import_location branch from 395e750 to 59abb71 Compare October 21, 2026 20:19
A file that no module type applies to has no module in the module graph,
so its "Unknown module type" error had neither a location nor an import
trace, and didn't say which import pulled the file in.

`handle_resolve_error` now keeps the location of the import with such a
file in the resolve result, and the file is reported there when it turns
out to be needed as a module. A file that is only resolved, e.g. traced,
is still not reported. Files resolved without a known import location are
reported without a location, as before.
@lukesandberg
lukesandberg force-pushed the unknown_module_type_import_location branch from 59abb71 to 3f8a865 Compare October 22, 2026 01:16

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

created-by: Turbopack team PRs by the Turbopack team. tests Turbopack Related to Turbopack with Next.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant