next-transpile-modules
works great for Next projects, but how do I transpile modules for a raw SWC build??? I stumped
Repo: https://github.com/deltaepsilon/script-kitty
I started from a Turborepo base and exported two packages, ui
and command-k
into a Turborepo Next app named web
. Everything worked great once I added ui
and command-k
to the next.config.js
file like so:
const withTM = require('next-transpile-modules')(['command-k', 'ui']);
module.exports = withTM({
reactStrictMode: true,
});
Now I've got a new app named external
that's going to be a standalone build of the command-k
package. This will get published to npm.
I'm using swc-loader
to transpile it with the following config:
const path = require('path');
// See https://github.com/iykekings/react-swc-loader-template
const config = {
mode: 'development',
entry: './index.tsx',
module: {
rules: [
{
test: /\.(ts|tsx)$/,
loader: 'swc-loader',
include: [
path.resolve(__dirname),
path.resolve(__dirname, '../../packages/command-k'),
path.resolve(__dirname, '../../packages/ui'),
],
exclude: /node_modules/,
},
],
},
};
module.exports = config;
I keep getting the following error when building with yarn dev
:
ERROR in ../../packages/command-k/index.tsx 2:0-50
Module not found: Error: Can't resolve './command-k' in '/kitty/packages/command-k'
resolve './command-k' in '/kitty/packages/command-k'
using description file: /kitty/packages/command-k/package.json (relative path: .)
// /packages/command-k/index.tsx
import * as React from 'react';
export { default as CommandK } from './command-k';
It looks like swc-loader
is somehow unable to import from inside of a Turborepo package. It works fine if I inline the contents of ./command-k
into /packages/command-k/index.tsx
, but swc-loader
refuses to follow the import.