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
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
- chore(es/module): Remove `serde(deny_unknown_fields)` (#8163) **Related issue:** - Closes #7979 — committed to swc-project/swc by kdy1 8 months ago
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 warningSo 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.