Skip to content

Cannot use Next.js as a transitive dep to build an application #73375

Open
@Ethan-Arrowood

Description

@Ethan-Arrowood

Link to the code that reproduces this issue

https://github.com/Ethan-Arrowood/next-issue-repro

To Reproduce

Follow readme in https://github.com/Ethan-Arrowood/next-issue-repro

Or:

  1. Generate a new nextjs app, npx create-next-app. Called it my-app
  2. As a sibling to the next app created in step 1, create a new directory next-transitive
  3. Add a package.json with the content: { "dependencies": { "next-app": "file:../my-app" } }
  4. cd into next-transitive and run npm install --install-links (the option is so that the file: is actually installed instead of symlinked)
  5. cd into node_modules/next-app and try to run npx next build or npm run build. They will both fail with the following:
> [email protected] build
> next build

   ▲ Next.js 15.0.3

   Creating an optimized production build ...
Failed to compile.

./app/page.js
Module parse failed: Unexpected token (6:4)
File was processed with these loaders:
 * ../next/dist/build/webpack/loaders/next-flight-loader/index.js
 * ../next/dist/build/webpack/loaders/next-swc-loader.js
You may need an additional loader to handle the result of these loaders.
| export default function Home() {
|   return (
>     <div className={styles.page}>
|       <main className={styles.main}>
|         <Image

Import trace for requested module:
./app/page.js


> Build failed because of webpack errors

Current vs. Expected behavior

This behavior seems to exist for a few major versions. My assumption is that the build process is not resolving its own dependencies correctly.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6030
  Available memory (MB): 18432
  Available CPU cores: 12
Binaries:
  Node: 20.16.0
  npm: 10.8.1
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.0.3 // Latest available version is detected (15.0.3).
  eslint-config-next: N/A
  react: 19.0.0-rc-66855b96-20241106
  react-dom: 19.0.0-rc-66855b96-20241106
  typescript: N/A
Next.js Config:
  output: N/A

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

Developer Experience, Script (next/script), SWC, Webpack

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

next build (local)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    SWCRelated to minification/transpilation in Next.js.Script (next/script)Related to Next.js Script Optimization.WebpackRelated to Webpack with Next.js.bugIssue was opened via the bug report template.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions