nextjs - ✅(Solved) Fix [Turbopack] Import statements are not resolved in the order specified in the resolve extensions config [2 pull requests, 4 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#91117Fetched 2026-04-08 00:18:55
View on GitHub
Comments
4
Participants
4
Timeline
16
Reactions
4
Timeline (top)
commented ×4referenced ×4cross-referenced ×2subscribed ×2

Error Message

Using Turbopack, the app throws an error while compiling the page because it tries to import React Native code. I assume this happens because it's not resolving the modules using the order specified in the resolve extensions config. The extension web.js should be evaluated before .js since that's the usual way third-party React Native libraries allow for React Native for Web usage.

Root Cause

Using Turbopack, the app throws an error while compiling the page because it tries to import React Native code. I assume this happens because it's not resolving the modules using the order specified in the resolve extensions config. The extension web.js should be evaluated before .js since that's the usual way third-party React Native libraries allow for React Native for Web usage.

Fix Action

Fixed

PR fix notes

PR #91145: test: add e2e test for resolve extensions order in Turbopack

Description (problem / solution / changelog)

Fixing a bug

What?

Adds an e2e test to verify that Turbopack respects the order specified in the resolveExtensions configuration when resolving import statements.

Why?

Currently, Turbopack does not resolve import statements in the order specified in the resolveExtensions config. When multiple files exist with different extensions (e.g., greeting.js and greeting.web.js), Turbopack should prioritize the extension that appears first in the resolveExtensions array, but it currently doesn't follow this behavior consistently with webpack.

How?

The test creates a scenario where:

  1. Two versions of the same module exist: greeting.js and greeting.web.js
  2. The next.config.js specifies .web.js should be resolved before .js in the resolveExtensions array
  3. Both server-side and client-side components import the module without an extension
  4. The test verifies that the .web.js variant is loaded in both cases

The test includes:

  • Server component that imports ./greeting (should resolve to greeting.web.js)
  • Client component that imports ./client-greeting (should resolve to client-greeting.web.js)
  • Next.js config with Turbopack resolveExtensions putting .web.js before .js
  • E2e test that checks both server-side rendering and client-side hydration

Fixes #91117

Changed files

  • test/e2e/app-dir/resolve-extensions-order/app/client-component.tsx (added, +7/-0)
  • test/e2e/app-dir/resolve-extensions-order/app/client-greeting.js (added, +4/-0)
  • test/e2e/app-dir/resolve-extensions-order/app/client-greeting.web.js (added, +4/-0)
  • test/e2e/app-dir/resolve-extensions-order/app/greeting.js (added, +6/-0)
  • test/e2e/app-dir/resolve-extensions-order/app/greeting.web.js (added, +5/-0)
  • test/e2e/app-dir/resolve-extensions-order/app/layout.tsx (added, +7/-0)
  • test/e2e/app-dir/resolve-extensions-order/app/page.tsx (added, +11/-0)
  • test/e2e/app-dir/resolve-extensions-order/next.config.js (added, +31/-0)
  • test/e2e/app-dir/resolve-extensions-order/resolve-extensions-order.test.ts (added, +27/-0)

Code Example

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.2.0: Tue Nov 18 21:07:05 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6020
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 24.11.1
  npm: 11.6.2
  Yarn: 1.22.22
  pnpm: 10.26.2
Relevant Packages:
  next: 16.2.0-canary.85 // Latest available version is detected (16.2.0-canary.85).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 5.9.3
Next.js Config:
  output: N/A

---

const nextConfig: NextConfig = {
  turbopack: {
    resolveAlias: {
      "react-native": "react-native-web",
    },
    resolveExtensions: [
      ".web.js",
      ".web.jsx",
      ".web.ts",
      ".web.tsx",
      ".mdx",
      ".tsx",
      ".ts",
      ".jsx",
      ".js",
      ".mjs",
      ".json",
    ],
    root: __dirname,
  },

  webpack: (config) => {
    config.resolve.alias = {
      ...(config.resolve.alias || {}),
      // Transform all direct `react-native` imports to `react-native-web`
      "react-native$": "react-native-web",
    };
    config.resolve.extensions = [
      ".web.js",
      ".web.jsx",
      ".web.ts",
      ".web.tsx",
      ...config.resolve.extensions,
    ];
    return config;
  },
};
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/gabrieltrompiz/turbopack-rn-reproduction-app

To Reproduce

  1. Start the application in dev mode (pnpm dev, yarn dev or npm run dev)
  2. Go to localhost:3000 (or whatever port Next is using)

Current vs. Expected behavior

Using Turbopack, the app throws an error while compiling the page because it tries to import React Native code. I assume this happens because it's not resolving the modules using the order specified in the resolve extensions config. The extension web.js should be evaluated before .js since that's the usual way third-party React Native libraries allow for React Native for Web usage.

If Webpack is used (with --webpack flag), then the application compiles successfully. I would expect the resolve extensions from Turbopack to work similarly to how Webpack resolve extensions option works.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.2.0: Tue Nov 18 21:07:05 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6020
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 24.11.1
  npm: 11.6.2
  Yarn: 1.22.22
  pnpm: 10.26.2
Relevant Packages:
  next: 16.2.0-canary.85 // Latest available version is detected (16.2.0-canary.85).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Turbopack

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local)

Additional context

Next config being used:

const nextConfig: NextConfig = {
  turbopack: {
    resolveAlias: {
      "react-native": "react-native-web",
    },
    resolveExtensions: [
      ".web.js",
      ".web.jsx",
      ".web.ts",
      ".web.tsx",
      ".mdx",
      ".tsx",
      ".ts",
      ".jsx",
      ".js",
      ".mjs",
      ".json",
    ],
    root: __dirname,
  },

  webpack: (config) => {
    config.resolve.alias = {
      ...(config.resolve.alias || {}),
      // Transform all direct `react-native` imports to `react-native-web`
      "react-native$": "react-native-web",
    };
    config.resolve.extensions = [
      ".web.js",
      ".web.jsx",
      ".web.ts",
      ".web.tsx",
      ...config.resolve.extensions,
    ];
    return config;
  },
};

extent analysis

Fix: Correct Turbopack resolve configuration

Turbopack does not read the keys resolveAlias / resolveExtensions that Webpack uses.
Instead it expects a nested resolve object (alias + extensions). Because the config was using the wrong shape, Turbopack fell back to its default order (.js before .web.js) and pulled the native RN entry‑points.

1️⃣ Update next.config.js

/** @type {import('next').NextConfig} */
const nextConfig = {
  // -----------------------------------------------------------------
  // Turbopack specific options (only used when running with --turbo)
  // -----------------------------------------------------------------
  turbopack: {
    // NOTE:

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING