Skip to content

Production build breaks due to invalid import; do not import from nuxt/app directly #247

@IlyaSemenov

Description

@IlyaSemenov

Following #240, specifically this comment: #240 (comment),

the current module needs to be transpiled, or it breaks in SSR mode. While transpiling indeed "fixes" the problem, this is a workaround with its own issues, not a proper fix.

See discussion in nuxt/nuxt#34662.

From what I gathered, the problem is apparently that the module does this:

import { useAsyncData, useRequestHeaders } from "nuxt/app"

I suspect that useAsyncData is not supposed to be used like this because it has compile-time magic (auto-generating data key) and should not bypass the Nuxt compiler.

I see the following ways we could truly address this:

  1. trpc-nuxt could be converted into a "true" module (doing defineNuxtModule and injecting runtime code with addPlugin, addComposable, etc.)
  2. If there are low-level counterparts to useAsyncData and useRequestHeaders, they should be used instead. nuxt/app should not be imported from third party code, it's only supposed to be imported from within a Nuxt app.
  3. Simply revert Remove outdated transpilation requirement from setup docs #241, get back to using { transpile: ['trpc-nuxt'] }, but then ideally we should provide a recipe to avoid transpiling the underlying @trpc/client, or at the very least document the gotcha (being unable to use error instanceof TRPCClientError). Or, perhaps re-export the transpiled TRPCClientError?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions