swc: [Wrong] Es6/nodenext module only has a field named `resolveFully` and you should remove other fields.

Describe the bug

Since @swc/core@1.3.80, my project - @ducanh2912/next-pwa - has been seeing this issue:

For me - building the package using rollup with @rollup/plugin-swc:

src/index.ts → dist/index.cjs, dist/index.module.js...
[!] (plugin swc) Error: unknown field `lazy`, expected `resolveFully` at line 1 column 444
src/index.ts
Error: unknown field `lazy`, expected `resolveFully` at line 1 column 444

For people who use my project:

 x (pwa) Failed to build the fallback worker.
 x (pwa) assets by status 268 bytes [cached] 1 asset
./node_modules/.pnpm/@ducanh2912+next-pwa@9.7.0_next@13.5.1_webpack@5.88.2/node_...(truncated) 39 bytes [built] [code generated] [1 error]

ERROR in ./node_modules/.pnpm/@ducanh2912+next-pwa@9.7.0_next@13.5.1_webpack@5.88.2/node_modules/@ducanh2912/next-pwa/dist/fallback.js
Module build failed (from ./node_modules/.pnpm/@ducanh2912+next-pwa@9.7.0_next@13.5.1_webpack@5.88.2/node_modules/@ducanh2912/next-pwa/dist/swc-loader.cjs):
Error: unknown field `lazy`, expected `resolveFully` at line 1 column 639

webpack 5.86.0 compiled with 1 error in 238 ms

This seems to only stop happening if I remove module.lazy and module.noInterop from .swcrc, but they don’t seem to have been removed at all, which tells me that this is likely a bug.

Input code

Link to the repo: https://github.com/DuCanhGH/next-pwa/tree/master/packages/next-pwa

Code compiled on users’ end:

self.fallback = async (request) => {
  // https://developer.mozilla.org/en-US/docs/Web/API/RequestDestination
  const { destination, url } = request;
  const fallbackUrl: Partial<Record<RequestDestination, string | undefined>> = {
    document: process.env.__PWA_FALLBACK_DOCUMENT__,
    image: process.env.__PWA_FALLBACK_IMAGE__,
    audio: process.env.__PWA_FALLBACK_AUDIO__,
    video: process.env.__PWA_FALLBACK_VIDEO__,
    font: process.env.__PWA_FALLBACK_FONT__,
  };
  const fallbackResponse = fallbackUrl[destination];
  if (fallbackResponse) {
    return caches.match(fallbackResponse, {
      ignoreSearch: true,
    });
  }
  if (
    destination === "" &&
    process.env.__PWA_FALLBACK_DATA__ &&
    url.match(/\/_next\/data\/.+\/.+\.json$/i)
  ) {
    return caches.match(process.env.__PWA_FALLBACK_DATA__, {
      ignoreSearch: true,
    });
  }
  return Response.error();
};

// Mark file as module.
export {};

Config

Config used to compile the package itself:

// @ts-check
/**
 * @type {import("@swc/core").Config}
 */
export const swcConfig = {
  module: {
    type: "nodenext",
    lazy: true,
    importInterop: "swc",
  },
  jsc: {
    minify: {
      compress: {
        ecma: 5,
        comparisons: false,
        inline: 2,
      },
      mangle: {
        safari10: true,
      },
      format: {
        ecma: 5,
        safari10: true,
        comments: false,
        asciiOnly: true,
      },
    },
    parser: {
      syntax: "typescript",
      tsx: false,
      dynamicImport: true,
      decorators: false,
    },
    transform: {
      react: undefined,
    },
    target: "esnext",
    loose: false,
  },
};

Config used to compile on users’ end:

import type { Options } from "@swc/core";

export const defaultSwcRc: Options = {
  module: {
    type: "es6",
    lazy: true,
    noInterop: true,
  },
  jsc: {
    parser: {
      syntax: "typescript",
      tsx: true,
      dynamicImport: true,
      decorators: false,
    },
    transform: {
      react: {
        runtime: "automatic",
      },
    },
    loose: false,
  },
  minify: false,
};

Playground link

https://play.swc.rs/?version=1.3.80&code=H4sIAAAAAAAAA5VTwW4aMRC98xWjqIpApfadZJG2gVSooSASmkOJLMeeBTdee2t7Udp0%2F70GdpOoSBvl4Iv95r03bzwedUYyrvU9Fw%2BQAPe%2FjYCuw18l%2BtCDZAhPHQBKYRNC4QeUStyitgU6kts%2FSmtOrFtTNJ%2BW11Ra4ekt3tN0PqGLA8coHmV4UNZEImGND%2FAE8uW2D6XTUEXxWvXsGdcYWzo9gDl3QXF9vkBhnTw%2Fpu%2BDD06ZNfyF0kjMlEE5HEbeXQcA0VyZowkDKJwV6D1BsyWMzW9TdpleXX1OL76y0exiOR1%2Fu2Gsvy9SOV9ja8Vkmn4ZN3BeSmVb4elyNJk18K2S2A7%2FPhmNn%2BGZfcP95axxXh2HuEBfxAuMgbzK9cerSdztilQG3f9LenWEDkPpDAguNuhJzoPYHGH7NTYyrY11eI3cic0Agivx0EbV2%2BlUtdZhNi8mIEkSODmB09P9S9us0puUsQYYP1HtiK4oM%2FgYVlTywFeUfNwf8tNb84GqXoS3NfSm4ns6rAWacAg6Z103PscBdeJWTbl7gExpjJsHuZWlRtLBx8K6uCXV2T%2B8Oe6unwMAAA%3D%3D&config=H4sIAAAAAAAAA1WPQQ7DIAwE731FxLnnHvqDPsMijkQFGNlGCq34eyFBaXLcWWnH%2Ft6myQSas0fznL4ttawl9WRQHua%2BIw%2Bf0pByxkEivaIiUxq40dor8xb7n0rAgnzkRqREhbXPd41YdkmHpatlvWgamtESgxJLaxbwgltTxx3KEGUhDmcJI1g9gY5yVBe2vyArBVBnzajrZdETCZ5c%2B1vBRbeUA9cfInoy3ToBAAA%3D

SWC Info output

Operating System:
    Platform: linux
    Arch: x64
    Machine Type: x86_64
    Version: #1 SMP PREEMPT_DYNAMIC Wed, 06 Sep 2023 21:01:01 +0000
    CPU: (12 cores)
        Models: AMD Ryzen 5 5500

Binaries:
    Node: 18.16.0
    npm: 9.5.1
    Yarn: 1.22.19
    pnpm: 8.7.5

Relevant Packages:
    @swc/core: 1.3.86
    @swc/helpers: N/A
    @swc/types: N/A
    typescript: 5.3.0-dev.20230915
    next: 13.4.19

SWC Config:
    output: N/A
    .swcrc path: N/A

Next.js info:
    output: N/A

Expected behavior

This issue shouldn’t happen, and the code should be compiled successfully like in @swc/core@1.3.78 and below.

Actual behavior

The error happens as described in section “Describe the bug”.

Version

1.3.86

Additional context

On users’ end, seems that even installing @swc/core@1.3.8x works (this forces next-pwa to resolve to that swc instead of Next’s internal swc), but this is not the case for the package itself. Only by pinning @swc/core to 1.3.78 can I get it to build.

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Reactions: 3
  • Comments: 18 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I can change the type if required, but in future.

I expected ts-node to fix it more promptly. I’ll change this error to warning

So if a bug made a program of user work where it should not, the bug should never be fixed without marking it as a breaking change, right? Do you really think this makes sense?

It’s closed becauae it’s not a bug. It’s about a wrong configuration.