swc-jotai icon indicating copy to clipboard operation
swc-jotai copied to clipboard

Next.js 15.2.0 runtime and build errors using `@swc-jotai/react-refresh`

Open n2k3 opened this issue 9 months ago • 0 comments

When using the latest Next.js 15.2.0 in my existing project it causes these errors. The error happening during build, seems to be the same as https://github.com/pmndrs/swc-jotai/issues/44 (or close to).

How to reproduce

  1. Clone a new repo using bunx create-next-app@latest --yes (use any name for the new project)
  2. Add packages via bun i -D @swc-jotai/react-refresh
  3. Add this to next.config.ts
    import type { NextConfig } from "next";
    
    const nextConfig: NextConfig = {
    -  /* config options here */
    +  experimental: {
    +    swcPlugins: [["@swc-jotai/react-refresh", {}]],
    +  }
    };
    
    export default nextConfig;
    
  4. Run next dev or next dev --turbopack or next build
  5. See errors below
Error from dev server with turbopack

Command next dev --turbopack:

 ⨯ ./node_modules/next/dist/esm/build/templates/pages.js:3:1
Module not found: Can't resolve 'next/dist/esm/build/templates/helpers'
failed to analyse ecmascript module '[project]/node_modules/next/dist/esm/build/templates/helpers.js [ssr] (ecmascript)'

Caused by:
- failed to parse [project]/node_modules/next/dist/esm/build/templates/helpers.js
- Transforming and/or parsing of [project]/node_modules/next/dist/esm/build/templates/helpers.js failed
- wasm plugin bytecheck failed "failed without error information; enable debug assertions and the `alloc` feature in rancor for error information"

Debug info:
- Execution of <ModuleAssetContext as AssetContext>::process_resolve_result failed
- Execution of apply_module_type failed
- Execution of <EcmascriptModuleAsset as EcmascriptChunkPlaceable>::get_exports failed
- Execution of analyse_ecmascript_module failed
- failed to analyse ecmascript module '[project]/node_modules/next/dist/esm/build/templates/helpers.js [ssr] (ecmascript)'
- Execution of <EcmascriptModuleAsset as EcmascriptParsable>::failsafe_parse failed
- Execution of parse failed
- failed to parse [project]/node_modules/next/dist/esm/build/templates/helpers.js
- Transforming and/or parsing of [project]/node_modules/next/dist/esm/build/templates/helpers.js failed
- wasm plugin bytecheck failed "failed without error information; enable debug assertions and the `alloc` feature in rancor for error information"
Import map: aliased to module "next" with subpath '/dist/esm/build/templates/helpers' inside of [project]/
Error from dev server without turbopack

Command next dev --turbopack:

[Error: ENOENT: no such file or directory, open 'E:\src\next-latest-test\.next\fallback-build-manifest.json'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'E:\\src\\next-latest-test\\.next\\fallback-build-manifest.json'
}
Error from building

Command next build:

$ next build
   ▲ Next.js 15.2.0
   - Experiments (use with caution):
     · swcPlugins

   Creating an optimized production build ...
Failed to compile.

./node_modules/next/dist/client/components/app-router-headers.js
Error:   x failed to invoke plugin on 'Some("E:\\src\\next-latest-test\\node_modules\\next\\dist\\client\\components\\app-router-headers.js")'

Import trace for requested module:
./node_modules/next/dist/client/components/app-router-headers.js
./node_modules/next/dist/lib/url.js
./node_modules/next/dist/lib/metadata/resolvers/resolve-opengraph.js
./node_modules/next/dist/lib/metadata/resolve-metadata.js
./node_modules/next/dist/lib/metadata/metadata.js
./node_modules/next/dist/server/app-render/entry-base.js

./node_modules/next/dist/client/components/client-page.js
Error:   x failed to invoke plugin on 'Some("E:\\src\\next-latest-test\\node_modules\\next\\dist\\client\\components\\client-page.js")'

Import trace for requested module:
./node_modules/next/dist/client/components/client-page.js
./node_modules/next/dist/server/app-render/entry-base.js

./node_modules/next/dist/client/components/client-segment.js
Error:   x failed to invoke plugin on 'Some("E:\\src\\next-latest-test\\node_modules\\next\\dist\\client\\components\\client-segment.js")'

Import trace for requested module:
./node_modules/next/dist/client/components/client-segment.js
./node_modules/next/dist/server/app-render/entry-base.js

./node_modules/next/dist/client/components/error-boundary.js
Error:   x failed to invoke plugin on 'Some("E:\\src\\next-latest-test\\node_modules\\next\\dist\\client\\components\\error-boundary.js")'

Import trace for requested module:
./node_modules/next/dist/client/components/error-boundary.js

./node_modules/next/dist/client/components/forbidden-error.js
Error:   x failed to invoke plugin on 'Some("E:\\src\\next-latest-test\\node_modules\\next\\dist\\client\\components\\forbidden-error.js")'

Import trace for requested module:
./node_modules/next/dist/client/components/forbidden-error.js


> Build failed because of webpack errors
error: script "build" exited with code 1

Process finished with exit code 1

n2k3 avatar Feb 28 '25 06:02 n2k3