babel-plugin-superjson-next icon indicating copy to clipboard operation
babel-plugin-superjson-next copied to clipboard

Doesn't work with superjson@2

Open mongolyy opened this issue 2 years ago • 3 comments

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

  • Next.js version: 13.3.4
  • superjson version: 2.0.0
  • babel-plugin-superjson-next version: 0.4.4

mongolyy avatar Oct 19 '23 17:10 mongolyy

Any solutions?

baba43 avatar Apr 19 '24 15:04 baba43

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?

Skn0tt avatar Apr 19 '24 15:04 Skn0tt

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

remorses avatar Nov 01 '24 16:11 remorses