I'm trying to create an internal package in a turborepo project. The shared package follows the same setup as the example, and it works as is in the Vite frontend project. However, when importing that module to the backend (Nest + SWC) the dev script fails Unexpected token 'export'.
The built main.js file is trying to require from the shared package, but it's only a typescript file (as in the example). All the examples and other issues are using Next.js, which has a transpilePackages config option that does exactly what I'm trying to achieve. Is there an alternative to transpilePackages that works outside of Next.js? (preferably with SWC)
Things I've tried:
- including the shared package in
tsconfig.json - including it in
webpack.config.js(changing the exclude pattern ofswc-loaderto include that folder from node_modules)
There is a very similar issue to mine but it's still unresolved and uses Next.js.
Had the same thing, followed https://turbo.build/repo/docs/handbook/publishing-packages/bundling and it helped.
When I was trying to do the same with
"build": "tsc"in my package's package.json it didn't work properly, switching to"build": "tsup src/index.ts --format cjs,esm --dts"worked better for both the vite app and the commonjs backend I have.