Skip to content
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

Assets url resolution in CSS is different between build and dev (Turbopack) #76047

Open
cavez86 opened this issue Feb 14, 2025 · 3 comments
Open
Labels
CSS Related to CSS. linear: turbopack Confirmed issue that is tracked by the Turbopack team. Turbopack Related to Turbopack with Next.js.

Comments

@cavez86
Copy link

cavez86 commented Feb 14, 2025

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/recursing-murdock-stq8td

To Reproduce

  1. Import a CSS/SCSS containing a url('~@/path/to/asset.svg') (eg a background-image)
  2. Start the application in dev mode (with Turbopack)
  3. See the error even if the assets exists
  4. Remove the ~
  5. Dev mode works but build breaks

Current vs. Expected behavior

Turbopack supports only url('@/path/to/asset.svg') syntax.
Otherwise returns error Module not found: Can't resolve '~@/path/to/asset.svg'

Webpack supports only url('~@/path/to/asset.svg') syntax.
Otherwise returns error Module not found: Can't resolve './@/path/to/asset.svg'

A possible workaround is to set in next.config.ts

  experimental: {
    turbo: {
      resolveAlias: {
        '~@/*': '@/*',
      },
    },
  },

and use ~@ syntax.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 32449
  Available CPU cores: 8
Binaries:
  Node: 22.11.0
  npm: 10.9.0
  Yarn: 3.6.1
  pnpm: 10.2.1
Relevant Packages:
  next: 15.1.7 // Latest available version is detected (15.1.7).
  eslint-config-next: 15.1.7
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.3
Next.js Config:
  output: N/A

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

CSS

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

next dev (local)

Additional context

No response

@github-actions github-actions bot added the CSS Related to CSS. label Feb 14, 2025
@samcx
Copy link
Member

samcx commented Feb 14, 2025

@cavez86 This works fine if you just adjust the paths config in your tsconfig.json.

    "paths": {
      "~@/*": ["./*"]
    }

@samcx samcx added Module Resolution Module resolution (CJS / ESM, module resolving). and removed CSS Related to CSS. labels Feb 14, 2025
@cavez86
Copy link
Author

cavez86 commented Feb 15, 2025

@cavez86 This works fine if you just adjust the paths config in your tsconfig.json.

    "paths": {
      "~@/*": ["./*"]
    }

Ok, but shouldn't the same format be supported in dev and build mode by default?

@samcx
Copy link
Member

samcx commented Feb 20, 2025

Ok, but shouldn't the same format be supported in dev and build mode by default?

Hmm, I would expect it to not work at all (equally in dev and build) unless explicitly set.

@samcx samcx added Turbopack Related to Turbopack with Next.js. CSS Related to CSS. and removed Module Resolution Module resolution (CJS / ESM, module resolving). labels Feb 20, 2025
@mischnic mischnic added the linear: turbopack Confirmed issue that is tracked by the Turbopack team. label Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS Related to CSS. linear: turbopack Confirmed issue that is tracked by the Turbopack team. Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

No branches or pull requests

3 participants