简体   繁体   English

NX monorepo:应用程序使用库的源文件而不是 dist 文件夹中的源文件

[英]NX monorepo: application uses library's source files instead of ones from dist folder

Here is the problem: I use NX for monorepo.问题是:我将 NX 用于 monorepo。 There is an application written in angularJS (webpack for building). angularJS写了一个应用(webpack for building)。 It uses library that produces web components (react inside).它使用生成 web 个组件的库(内部反应)。

import { test } from "@lib/somelib"

The library successfully produces /dist folder (with index.js, react included, ts types).该库成功生成 /dist 文件夹(包含 index.js、react 和 ts 类型)。

The thing is that when I build main application, I get an error:问题是,当我构建主应用程序时,出现错误:

[tsl] ERROR in /Users/***/monorepo/packages/somelib/src/web-components/FirstWebComponent.tsx(33,5)
      TS17004: Cannot use JSX unless the '--jsx' flag is provided.
 @ ../somelib/src/web-components/index.ts 4:28-58
 @ ../somelib/src/index.ts 6:21-48
 @ ./app/scripts/app.ts 90:18-50

shouldn't it use the files from the /dist/packages/somelib/?它不应该使用 /dist/packages/somelib/ 中的文件吗? instead of trying to use the original ones from sources?而不是尝试使用来源中的原始内容?

here is my tsconfig.base.json这是我的 tsconfig.base.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "lib": ["es2017", "dom"],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": ".",
    "paths": {
       "@lib/somelib": ["packages/somelib/src/index.ts"]
    }
  },
  "exclude": ["node_modules", "tmp"]
}

it should take the compiled react library files.它应该采用已编译的反应库文件。 I tried to changed paths in tsconfig.base.json but no success:我尝试更改 tsconfig.base.json 中的路径但没有成功:

"paths": {
  "@lib/somelib": ["dist/packages/somelib"]
}

I also tried to add alias in application's webpack configuration,我还尝试在应用程序的 webpack 配置中添加别名,

resolve: {
    plugins: [new TsconfigPathsPlugin()],
    extensions: ['.tsx', '.ts', '.js', '.css', '.html'],
    alias: {
      "@lib/somelib": path.resolve(__dirname, "../../dist/packages/somelib/")
    }
},

After playing around a bit I found a solution: so I had to add the path to the typescript files so the IDE can recognise types (in file tsconfig.base.json:)玩了一会儿后,我找到了一个解决方案:所以我必须将路径添加到 typescript 文件,以便 IDE 可以识别类型(在文件 tsconfig.base.json 中:)

    "paths": {
      "@lib/ui-components": ["packages/ui-components/src/index.js"]
    }

then in the webpack.config.js:然后在 webpack.config.js 中:

   resolve: {
      extensions: ['.ts', '.js', '.css', '.html'],
      alias: {
        '@lib/ui-components': path.resolve(__dirname, '../../packages/ui-components/dist/index'),
      },
   }

but then when compiling AngularJS mainproject, compilation was screaming:但随后在编译 AngularJS 主项目时,编译尖叫:

[tsl] ERROR in /Users/myname/repo/AngularJS/app-monorepo/packages/ui-components/src/web-components/index.ts(1,33)
      TS6142: Module './FirstWebComponent' was resolved to '/Users/myname/repo/AngularJS/app-monorepo/packages/ui-components/src/web-components/FirstWebComponent.tsx', but '--jsx' is not set.

so I had to add in the AngualrJS tsconfig.json: (in compilerOptions所以我不得不在 AngualrJS tsconfig.json 中添加:(在 compilerOptions

    "jsx": "react-jsx"

now I can import web components library that includes react into AngularJS project, and IDE will prompt with proper types.现在我可以将包含 react 的 web 组件库导入到 AngularJS 项目中,IDE 将提示正确的类型。

import { SomeComponent } from "@lib/ui-components";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 libs 中的 react 库中的 css 文件导入 nx 集成 monorepo 中的 next.js 应用程序? - How to import css files from react library inside libs to next.js app in nx integrated monorepo? Nx Monorepo - 如何在主 Nest 应用程序中使用 NestJs 库 - Nx Monorepo - How to Use NestJs Library inside the Main Nest App 使用源代码作为npm库发布到github,但在安装时应获取dist中存在的文件 - Publish as npm library to github with source code but on install should get the files present in dist 如何在@nrwl/nx monorepo 中导入绝对路径? - How to import absolute paths in a @nrwl/nx monorepo? NX 和 NextJS monorepo 中的全局类型声明 - Global Type Declarations within a NX and NextJS monorepo 无法从dist文件夹中的webpack生成的index.html中引用javascript和css文件 - not able to reference javascript and css files from my index.html generated by webpack in dist folder Webpack-无法生成编译文件,甚至dist文件夹 - Webpack - Failed to generate the compiled files, or even the dist folder Nx 共享资产库 - Nx shared asset library 创建 React 应用程序 - 如何将 pdf.worker.js 文件从 pdfjs-dist/build 复制到项目的 output 文件夹? - Create react app - how to copy pdf.worker.js file from pdfjs-dist/build to your project's output folder? 使用 React 在 monorepo 中从另一个 package 导入 JSX 文件时出错 - Error when importing JSX files from another package in monorepo with React
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM