blitz-js / next-superjson-plugin

SuperJSON Plugin for Next.js Pages and Components
192 stars 13 forks source link

Jest Error: Cannot find module 'next-superjson-plugin/tools' #75

Closed mauriceackel closed 1 year ago

mauriceackel commented 1 year ago

Verify Next.js canary release

Describe the bug

After upgrading from 0.4.x to 0.5.6 I get an error when trying to run my test with Jest.

After investigation, it seems that this plugin adds an import to my pages. The import seems to be:

import { withSuperJSONPage as _withSuperJSONPage } from "next-superjson-plugin/tools";

In PR 57, there seems to have been a change too how the library is packaged. This leads to a case where the typescript resolver cannot resolve next-superjson-plugin/tools anymore.

I verified this by trying to import from this module path manually, which failed. The only path I can import from is next-superjson-plugin/dist/tools

PLEASE NOTE: Building the actual application still works and I believe this is due to exports configuration in your package.json. The bug is only related to type resolution with TypeScript

Expected behavior

I would expect that after the upgrade to v5, module resolution in TypeScript still works like before.

I think the package.json has to be adapted to reflect the new folder layout for TypeScript module resolution.

Reproduction link

No response

Version

0.5.6

Config

No response

Additional context

No response

mauriceackel commented 1 year ago

My workaround for now is to downgrade to a version 0.4.x

orionmiz commented 1 year ago

You can change moduleResolution option for tsconfig.json

{
  "compilerOptions": {
    "moduleResolution": "node16",
  }
}

or

{
  "compilerOptions": {
    "moduleResolution": "nodenext",
  }
}