image icon indicating copy to clipboard operation
image copied to clipboard

ERROR: The symbol "useImage" has already been declared when build

Open dev3h opened this issue 4 months ago • 5 comments

I’m encountering the following error: The symbol "useImage" has already been declared. I’ve verified that I’m not using any composable named useImage. Has anyone else encountered this issue?

dev3h avatar Aug 08 '25 02:08 dev3h

On @nuxt/image 1.11.0, I got this when upgrading rolldown-vite from 7.1.0 to 7.1.1+. I don't use useImage anywhere in my code, I just use the NuxtImg component.

Downgrading @nuxt/image to 1.10.0 seems to work, i'm assuming this is because they expose nitro server helpers (#1473).

Only occurs for me when doing a nuxt build, and only when nitro is building.

I can't seem create a reproduction in stackblitz, I'll try investigating more. It could be an intermittent issue, as my builds used to work on windows and failed in docker but now they both broke.

n-rowe avatar Aug 12 '25 16:08 n-rowe

Oh wow, thank you so much, you saved me a lot of time. When I reinstall version 1.10.0, when I build, there is no error. I don't use rolldown-vite, so I can't help you. Maybe another developer can help you make a solution to this problem

dev3h avatar Aug 14 '25 02:08 dev3h

On @nuxt/image 1.11.0, I got this when upgrading rolldown-vite from 7.1.0 to 7.1.1+. I don't use useImage anywhere in my code, I just use the NuxtImg component.

Downgrading @nuxt/image to 1.10.0 seems to work, i'm assuming this is because they expose nitro server helpers (#1473).

Only occurs for me when doing a nuxt build, and only when nitro is building.

I can't seem create a reproduction in stackblitz, I'll try investigating more. It could be an intermittent issue, as my builds used to work on windows and failed in docker but now they both broke.

For the sake of tracking the issue, this is the esbuild error I get.

ERROR  Transform failed with 1 error:
/app/.nuxt/dist/server/_nuxt/NuxtImg-CqNePPnM.js:273:3: ERROR: The symbol "useImage" has already been declared
    at failureErrorWithLog (node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1467:15)
    at node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:736:50
    at responseCallbacks.<computed> (node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:603:9)
    at handleIncomingPacket (node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:658:12)
    at Socket.readFromStdout (node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:581:7)
    at Socket.emit (node:events:507:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at Pipe.onStreamRead (node:internal/stream_base_commons:189:23)

When I checked /app/.nuxt/dist/server/_nuxt/NuxtImg-CqNePPnM.js:273:3: I could only see one declaration of useImage, and I compared the built files to @nuxt/image 1.10.0 and they are almost identical.

n-rowe avatar Aug 14 '25 09:08 n-rowe

The issue is related to auto imports. It seems it's auto importing the server utils. Adding the following to the nuxt config:

nitro: {
  imports: {
    autoImport: false
  }
}

Resolves the build issue, but breaks running the server (for me at least)

n-rowe avatar Aug 14 '25 10:08 n-rowe

Resolves the build issue, but breaks running the server (for me at least)

Settled on excluding the NuxtImg component for nitro auto imports.

nitro: {
  imports: {
    exclude: /NuxtImg-.*\.js/,
  }
}

Seems to build and run for me, i'm not sure why nitro is trying to auto import server utilities in vue components.

n-rowe avatar Aug 14 '25 10:08 n-rowe