[英]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.