blitz-js / babel-plugin-superjson-next

Automatically transform your Next.js Pages to use SuperJSON
MIT License
124 stars 15 forks source link

Doesn't work with superjson@2 #145

Open mongolyy opened 1 year ago

mongolyy commented 1 year ago

When I upgraded superjson to version 2.0.0 and ran the next build command, I got the following error:

info  - Collecting page data ...Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\mongolyy\repos\next-app\node_modules\superjson\dist\index.js from C:\Users\mongolyy\repos\next-app\node_modules\babel-plugin-superjson-next\dist\tools.js not supported.
Instead change the require of index.js in C:\Users\mongolyy\repos\next-app\node_modules\babel-plugin-superjson-next\dist\tools.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (C:\Users\mongolyy\repos\next-app\node_modules\babel-plugin-superjson-next\dist\tools.js:64:19)
    at Object.<anonymous> (C:\Users\mongolyy\repos\next-app\node_modules\babel-plugin-superjson-next\tools.js:1:18)
    at 1421 (C:\Users\mongolyy\repos\next-app\.next\server\pages\cart.js:701:18)
    at __webpack_require__ (C:\Users\mongolyy\repos\next-app\.next\server\webpack-runtime.js:25:42)
    at C:\Users\mongolyy\repos\next-app\.next\server\pages\cart.js:66:91
    at __webpack_require__.a (C:\Users\mongolyy\repos\next-app\.next\server\webpack-runtime.js:89:13)
    at 8285 (C:\Users\mongolyy\repos\next-app\.next\server\pages\cart.js:60:21)
    at __webpack_require__ (C:\Users\mongolyy\repos\next-app\.next\server\webpack-runtime.js:25:42)
    at C:\Users\mongolyy\repos\next-app\.next\server\pages\cart.js:18:83
    at __webpack_require__.a (C:\Users\mongolyy\repos\next-app\.next\server\webpack-runtime.js:89:13)
    at 4411 (C:\Users\mongolyy\repos\next-app\.next\server\pages\cart.js:11:21)
    at __webpack_require__ (C:\Users\mongolyy\repos\next-app\.next\server\webpack-runtime.js:25:42)
    at __webpack_exec__ (C:\Users\mongolyy\repos\next-app\.next\server\pages\cart.js:914:39)
    at C:\Users\mongolyy\repos\next-app\.next\server\pages\cart.js:915:85
    at __webpack_require__.X (C:\Users\mongolyy\repos\next-app\.next\server\webpack-runtime.js:177:21)
    at C:\Users\mongolyy\repos\next-app\.next\server\pages\cart.js:915:47
    at Object.<anonymous> (C:\Users\mongolyy\repos\next-app\.next\server\pages\cart.js:918:3)
    at requirePage (C:\Users\mongolyy\repos\next-app\node_modules\next\dist\server\require.js:156:12)
    at C:\Users\mongolyy\repos\next-app\node_modules\next\dist\server\load-components.js:68:84
    at async loadComponentsImpl (C:\Users\mongolyy\repos\next-app\node_modules\next\dist\server\load-components.js:68:26)
    at async C:\Users\mongolyy\repos\next-app\node_modules\next\dist\build\utils.js:1002:32
    at async Span.traceAsyncFn (C:\Users\mongolyy\repos\next-app\node_modules\next\dist\trace\trace.js:103:20) {
  code: 'ERR_REQUIRE_ESM'
}

I think this is due to superjson becoming ES Module in 2.0.0.

Environement

baba43 commented 6 months ago

Any solutions?

Skn0tt commented 6 months ago

This might be related to settings in your tsconfig.json or the type field in your package.json. When you put import SuperJSON from "superjson" into one of your source files, does it fail with the same error?

remorses commented 1 week ago

You are distributing this package as commonjs while you also migrated superjson to use ESM, which is incompatible