Skip to content

Resolving files with querystring #319

@lforst

Description

@lforst

Hi, I am one of the maintainers of the @sentry/nextjs SDK and we recently got a bug report stating that we mess up the output of @vercel/nft. This is completely valid and reproducible.

What we're doing in the SDK is that we have a webpack loader that "proxies" user files and re-exports wrapped versions of particular functions (i.e. Next.js data fetching methods and API routes).

For the proxying mechanism we first replace the user-file with a proxy-file, from which we then import the user-file with a query string at the end to mark it as "already proxied" to avoid infinite loops (e.g. import * as wrapee from './page.js?__sentry_wrapped__'). The rollup docs explain this rather well.

For some reason this breaks the Next.js' nft file generation, leading to my first question: Do you know why this would be happening?

Webpack is able to resolve imports containing a query parameters - it simply strips the query parameter when looking for the file in the file system. Is nft also able to resolve these paths? I tried using nft why to experiment but it seemed like it couldn't resolve it with the error:

Error: Failed to resolve dependency ./pages/index.js?__sentry_wrapped__:
Cannot find module '/workspaces/sentry-nextjs-vercel-testproject/pages/index.js?__sentry_wrapped__' loaded from /workspaces/sentry-nextjs-vercel-testproject/test.js

Do you know if there is a workaround for us or something we can do here? We would also be ready to contribute upstream to support query params and fragments in import paths.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions