/pnpm-ts5-swc-esm-jest

POC to test how PNPM, TypeScript v5, SWC, Jest and ESM can integrate together

Primary LanguageJavaScript

pnpm-ts5-swc-esm-jest

This POC is a continuation of the pnpm-ts-swc-esm POC.

For learnings and observations about PNPM, TS 4, SWC, or ESM, have a look at the README.

TS v5

Many quirks of TS v4 ESM support are not necessary anymore with TS v5.

The following has been removed from the Webpack Config:

// webpack.config.js

{
    resolve: {
        extensionAlias: {
            ".js": [".ts", ".tsx", ".js"]
        }
    }
}
// webpack.config.js

{
    module: {
        rules: [
            {
                test: /\.(js)$/,
                include: /node_modules/,
                resolve: {
                    fullySpecified: false
                }
            }
        ]
    }
}

And in the codebase, all the import paths has been updated to use their original file extension of of .js.

@swc/jest with ESM

Jest documentation still mark ESM support has being experimental.

However, after trying a basic example in this repository it seem to work perfectly fine.

There are still a few issues but none of them seems to really affect us:

The only issue seems to be with @swc/jest which doesn't pick up the .swcrc config file but it can be solved but providing the configuration directly in the Jest transformer has explained in this issue.

// jest.config.js

{
    transform: {
        "^.+\\.(t|j)sx?$": ["@swc/jest", {
            jsc: {
                transform: {
                    react: {
                    runtime: 'automatic',
                    }
                }
            },
            ...
        }]
    },
}

It's also important to add extensionsToTreatAsEsm to the Jest config file.

// jest.config.js

{
    extensionsToTreatAsEsm: [".ts", ".tsx"]
}