最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

angular - Tailwind unable to resolve import to library via paths in Nx - Stack Overflow

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论