Skip to content

How to make typescript path alias of a dependency workspace work? #4555

Closed Answered by yf-yang
yf-yang asked this question in Q&A
Discussion options

You must be logged in to vote

Got it work, I wrote a webpack plugin similar to https://github.com/dividab/tsconfig-paths-webpack-plugin/blob/master/src/plugin.ts

To enable:

// next.config.mjs
import { MonorepoResolvePlugin } from './monorepo-resolve-plugin.mjs';
const nextConfig = {
  webpack: (config) => {
    
    // ...other codes

    config.resolve = {
      ...config.resolve,
      plugins: [
        ...config.resolve.plugins,
        new MonorepoResolvePlugin({
          appRoot: process.cwd(),
          workspaceParents: [
            '../../apps',
            '/workspaces/nextjs-monorepo-example/packages/',
          ],
        }),
      ],
    };
  }
};
// monorepo-resolve-plugin.mjs

import path from 'path';

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@yf-yang
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by yf-yang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant