Chrillewoodz
Chrillewoodz

Reputation: 28338

Tailwind unable to resolve import to library via paths in Nx

I'm trying to find a way of importing a tailwind.config.ts file located in @myorg/tailwind, into one of my applications so each application can share the same configuration. However, any paths in the tsconfig.base.json file doesn't seem to work even when adding the application's tailwind.config.ts to the tsconfig.app.json's files property. It doesn't show an error in VSC after adding the file, but when compiling you get this error:

✘ [ERROR] Cannot find module '@myorg/tailwind'
Require stack:
- /apps/public/tailwind.config.ts [plugin angular-sass]

    angular:styles/global:styles:1:8:
      1 │ @import 'apps/public/src/styles.scss';
        ╵         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  This error came from the "onLoad" callback registered here:

    node_modules/@angular/build/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.js:115:22:
      115 │                 build.onLoad({ filter: language.fileFilter, names...

General setup

libs/tailwind/src/index.ts:

export * from './lib/tailwind.config';

tsconfig.base.json:

"paths": {
  "@myorg/tailwind": ["libs/tailwind/src/index.ts"]
}

apps/public/tailwind.config.ts:

import type { Config } from 'tailwindcss';
import { TAILWIND_CONFIG } from '@myorg/tailwind';

export default {
  ...TAILWIND_CONFIG,
  content: [...TAILWIND_CONFIG.content, './apps/public/src/**/*.{html,ts}'],
} satisfies Config;

apps/public/src/styles.scss (Angular app with ESBuild):

@config '../tailwind.config.ts';

Using import { TAILWIND_CONFIG } from '../../libs/tailwind/src'; works fine so it's related to paths specifically it seems, but my project doesn't allow relative imports to other projects so it's not a solution.

Upvotes: 0

Views: 62

Answers (0)

Related Questions