Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Using debug package causes bug with turbopack and @svgr/webpack #78804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
paul-vd opened this issue May 3, 2025 · 4 comments · May be fixed by #78962
Open

Using debug package causes bug with turbopack and @svgr/webpack #78804

paul-vd opened this issue May 3, 2025 · 4 comments · May be fixed by #78962
Labels
linear: turbopack Confirmed issue that is tracked by the Turbopack team. Turbopack Related to Turbopack with Next.js.

Comments

@paul-vd
Copy link
Contributor

paul-vd commented May 3, 2025

Link to the code that reproduces this issue

https://github.com/paul-vd/nextjs-debug-reproduction

To Reproduce

  1. Ensure you have a .env with DEBUG="acme*" (acme can be anything)
  2. Start the application bun run dev
  3. Open http://localhost:3000

Current vs. Expected behavior

I expected to see the next.js logo, but I observed the following error instead:

 ⨯ ./app/next.svg
Error evaluating Node.js code
TypeError: 'process.env' only accepts a configurable, writable, and enumerable data descriptor
    [at Function.save (/private/tmp/reproduction-app/node_modules/debug/src/node.js:205:21)]
    [at Function.enable (/private/tmp/reproduction-app/node_modules/debug/src/common.js:163:15)]
    [at setup (/private/tmp/reproduction-app/node_modules/debug/src/common.js:287:14)]
    [at Object.<anonymous> (/private/tmp/reproduction-app/node_modules/debug/src/node.js:240:37)]
    [at Module._compile (node:internal/modules/cjs/loader:1562:14)]
    [at Object..js (node:internal/modules/cjs/loader:1699:10)]
    [at Module.load (node:internal/modules/cjs/loader:1313:32)]
    [at Function._load (node:internal/modules/cjs/loader:1123:12)]
    [at TracingChannel.traceSync (node:diagnostics_channel:322:14)]
    [at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)]



./app/page.tsx:1:1
Export default doesn't exist in target module
> 1 | import NextLogo from "./next.svg";
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2 | export default function Home() {
  3 |   return (
  4 |     <div>

The export default was not found in module [project]/app/next.svg.js [app-rsc] (ecmascript).
The module has no exports at all.
All exports of the module are statically known (It doesn't have dynamic exports). So it's known statically that the requested export doesn't exist.

 ○ Compiling /_error ...
 ✓ Compiled /_error in 931ms
 GET / 500 in 4004ms
 ✓ Compiled /favicon.ico in 470ms
 GET /favicon.ico 500 in 524ms

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:47 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.13.1
  npm: 10.9.2
  Yarn: 1.22.22
  pnpm: 8.8.0
Relevant Packages:
  next: 15.4.0-canary.19 // Latest available version is detected (15.4.0-canary.19).
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.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)

Additional context

I have also tested without installing the debug, but the same issue occurs, I believe it might be a peer of other depenencies, from lock file:

  • @babel/traverse
  • @babel/helper-define-polyfill-provider
@github-actions github-actions bot added the Turbopack Related to Turbopack with Next.js. label May 3, 2025
@timneutkens
Copy link
Member

Used the reproduction to create a more minimal reproduction that highlights the Node.js error:

// custom-loader.js
module.exports = (source) => {
  process.env.TEST_THIS_THING = "def";

  return "export default () => null";
};
// next.config.ts
import type { NextConfig } from "next";
import { join } from "path";

const nextConfig: NextConfig = {
  /* config options here */
  reactStrictMode: true,
  turbopack: {
    rules: {
      "*.svg": {
        as: "*.js",
        loaders: [join(__dirname, "./custom-loader.js")],
      },
    },
  },
};

export default nextConfig;
TEST_THIS_THING=abc next dev --turbopack

It seems to only happen when trying to assign values to an env var that was already set before.

@timneutkens
Copy link
Member

Seems the root cause is here where process.env is turned into a proxy for webpack loaders:

@timneutkens
Copy link
Member

Verified it's indeed caused by that Proxy, even smaller reproduction in isolation:

// testthis.js
// Patch process.env to track which env vars are read
const originalEnv = process.env
const readEnvVars = new Set()
process.env = new Proxy(originalEnv, {
  get(target, prop) {
    if (typeof prop === 'string' && !readEnvVars.has(prop)) {
      // We register the env var as dependency on the
      // current transform and all future transforms
      // since the env var might be cached in module scope
      // and influence them all
      readEnvVars.add(prop)
    }
    return Reflect.get(target, prop)
  },
})

process.env.TEST_THIS_THING = 'def'
TEST_THIS_THING=abc node testthis.js        
/Users/timneutkens/projects/next.js/testthis.js:17
process.env.TEST_THIS_THING = 'def'
                            ^

TypeError: 'process.env' only accepts a configurable, writable, and enumerable data descriptor
    at Object.<anonymous> (/Users/timneutkens/projects/next.js/testthis.js:17:29)
    at Module._compile (node:internal/modules/cjs/loader:1364:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
    at Module.load (node:internal/modules/cjs/loader:1203:32)
    at Module._load (node:internal/modules/cjs/loader:1019:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
    at node:internal/main/run_main_module:28:49 {
  code: 'ERR_INVALID_OBJECT_DEFINE_PROPERTY'
}

Node.js v18.20.6
TEST_THIS_THING=abc node testthis.js

@timneutkens timneutkens added the linear: turbopack Confirmed issue that is tracked by the Turbopack team. label May 8, 2025
@timneutkens
Copy link
Member

Fixed the problem in #78962. Thanks for the reproduction! Very helpful 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear: turbopack Confirmed issue that is tracked by the Turbopack team. Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants