I'm trying to create an internal package in my turborepo project that uses pnpm as the package manager. The shared package follows the exact same setup as provided in the turborepo documentation, and it works as is in my vite frontend project. However, when importing that module to the backend (Nest + SWC using webpack) the dev script fails with SyntaxError: Unexpected token 'export'"

The nest project is trying to import from the shared package, which is only exporting interfaces and enums.

Things I've tried:

1. including it in webpack.config.js by changing the exclude pattern of swc-loader to include that folder from node_modules, like this:

const swcDefaultConfig = require("@nestjs/cli/lib/compiler/defaults/swc-defaults").swcDefaultsFactory().swcOptions;

module.exports = {
    node: {
        __dirname: true,
    },
    module: {
        rules: [
            {
                test: /\.ts$/,
                exclude: _ => /node_modules/.test(_) && !/node_modules\/(@packages)/.test(_),
                use: {
                    loader: "swc-loader",
                    options: swcDefaultConfig,
                },
            },
        ],
    },
};

2. Switching to npm This DOES solve the issue but I would prefer to use pnpm

3. Setting shamefully-hoist=true in npmrc This does not solve the issue

0

There are 0 answers