concourse-resource-types 相关问题


@types/material-ui 和官方的@mui/types 包有什么区别?

npm 包:@types/material-ui 和 @mui/types 我知道前者受到 Definely Typed 社区的支持,但如果存在官方类型包,为什么它首先存在呢?我已经


TypeScript Redux 在刷新页面时丢失状态

redux/reducer/cartReducer.ts 从“@reduxjs/toolkit”导入{createSlice,PayloadAction}; 从“../../types/reducer-types”导入{ CartReducerInitialState }; 导入 { 购物车项目,


@types/ws 尝试从角度 12 更新到角度 13 时出现错误

我已将我的项目从 Angular 12 更新为 Angular 13,但遇到此错误: 错误:node_modules/@types/ws/index.d.ts:328:18 - 错误 TS2315:类型“服务器”不是通用的。 328服务器?:


npm 包 mime 类型无法与打字稿(或 Nestjs)一起工作(给出未定义)

我尝试在 NestJs 中使用 mime 类型,如下所示。 从“mime-types”导入 mime; mime.contentType(req.url) 但是即使我已经安装了 mime-types npm 包,mime 也给了我未定义的信息。它确实...


为什么当我尝试安装另一个依赖项时会收到有关一个依赖项的错误?

当我尝试安装 @types/react 和 @types/react-dom 时,出现有关依赖项冲突的错误。这个错误是什么意思?我的 React-persian-datepicker 包出了什么问题?我认为


ChartJS 选项的类型?

有谁知道 ChartJS 是否有更新的类型集? 有一个包 @types/chartjs,但它已被弃用。 在定义选项时获得自动完成功能会很好。 目前与...


如何使用 ag 又名 the_silver_search 仅搜索目录?

我喜欢只搜索目录,选项 ag --list-file-types 对此没有帮助。坚持使用 ag 的原因是可以选择带有 --path-to-ignore 的文件,其中包含 pat...


Azure 自动化 Runbook - 返回错误的资源组名称。 “找不到资源组“{resource-group-name}””

我们在 Runbook 中使用以下代码,它返回的资源组名称值不正确。 $AzureVMs = Get-AzVM“SH-COMPANY-AD-0” $AzureVM | ForEach-对象 { $AzureV...


如何获取 Azure APIM 中操作策略的详细信息

有没有办法过滤并获取我的 APIM 中操作的所有策略。 我在 AZ CLI 中传递这一行: az apim api 操作显示 --resource-group $myResourceGroup --api-id $apiI...


az cli 命令在使用变量时返回“错误请求”,但否则有效

我有这个 Az cli 命令,可以为我想与脚本一起使用的虚拟机启用备份: #获取所需的虚拟机ID getID=$(az 虚拟机显示\ --resource-group $resourceGroup \ --name $vmName \ --曲...


在部署之前在本地测试 ARM 模板的任何工具

我以前从未在 Azure 上使用过 Docker 以及任何类似的东西,而且对于 Azure 来说还是个新手。 我对 ARM 模板有疑问。每当我尝试部署它时,都会收到错误:Either Resource Group al...


Velocity 在 Spring Boot 中找不到模板资源

我使用 Velocity 模板引擎在我的 Spring boot 应用程序中使用电子邮件模板发送电子邮件实用程序。 当前的代码如下所示。 pom.xml: 我正在使用 Velocity 模板引擎在我的 Spring boot 应用程序中使用电子邮件模板发送电子邮件实用程序。 当前代码如下所示。 pom.xml: <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> <version>1.7</version> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-tools</artifactId> <version>2.0</version> </dependency> 速度引擎 bean 配置: @Configuration public class VelocityConfig { @Bean public VelocityEngine velocityEngine() { VelocityEngine ve = new VelocityEngine(); ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); ve.init(); return ve; } } 电子邮件模板放置在 src/main/resources/email-templates/summary-email.vm <!DOCTYPE html> <head> <title>Summary</title> </head> <body> <h1>Claims Summary</h1> </body> </html> 放置在以下目录中: src ├── main │ ├── java │ │ └── com │ │ └── packageNameioot │ │ └── SpringBootApplication.java │ ├── resources │ │ ├── email-templates │ │ │ └── summary-email.vm │ │ └── application.properties 使用模板发送电子邮件的服务类: @Slf4j @Service @RequiredArgsConstructor public class EmailSummaryService { private final EmailConnector connector; private final VelocityEngine velocityEngine; public Mono<Void> sendFinanceClaimsRunEmailSummary(FinancePeriodRunEntity periodRunEntity, int successCount, int errorCount) { EmailDto emailDto = EmailDto.builder() .recipients(Set.of("[email protected]")) .subject("Claims summary") .body(createEmailBody()) .html(true) .build(); return connector.submitEmailRequest(emailDto); } private String createEmailBody() { VelocityContext context = new VelocityContext(); Template template = velocityEngine.getTemplate("email-templates/summary-email.vm"); StringWriter writer = new StringWriter(); template.merge(context, writer); return writer.toString(); } } 但是Velocity无法定位模板,出现以下错误。 ERROR velocity:96 - ResourceManager : unable to find resource 'email-templates/summary-email.vm' in any resource loader. org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'email-templates/summary-email.vm' 属性应该这样设置: VelocityEngine ve = new VelocityEngine(); ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); ve.setProperty("resource.loader.classpath.class", ClasspathResourceLoader.class.getName()); 根据 Apache Velocity Engine 文档。


将 YAML 文件注入构造函数

我有这个 YAML 文件 src/main/resources/foo.yml: 酒吧: - 你好 - 世界 巴兹: - 洛雷姆 - ipsum 这个组件: @成分 公共类我的组件{ 公共我的组件(地图 我有这个 YAML 文件 src/main/resources/foo.yml: bar: - hello - world baz: - lorem - ipsum 这个组件: @Component public class MyComponent { public MyComponent(Map<String, List<String>> foo) { // foo.get("bar") } } 使用 Spring Boot 2.7,是否可以将配置按原样(自己的文件,无前缀,无类)注入到构造函数中? 你可以这样做 @Configuration public class MyConfiguration { @Bean public Map<String, Object> foo(@Value("classpath:foo.yaml") Resource yaml) { Yaml yaml = new Yaml(); return yaml.load(yaml.getInputStream()); } } @Component public class MyComponent { public MyComponent(@Qualifier("foo") Map<String, Object> foo) { ... } }


使用 jquery javascript 搜索 jstree 节点

我正在使用 jstree 插件来构建我的树。我的网页中有一个搜索框,我需要用户能够在其中搜索 jstree 节点。 我正在使用 jstree 插件来构建我的树。我的网页中有一个搜索框,我需要用户能够在其中搜索 jstree 节点。 <fieldset id="search"> <input type="text" name="search_field" id="search_field" value="" /> <button id="search_tree">Search</button> </fieldset> 单击搜索时,jstree 节点应展开,如果找到,节点应突出显示。如果未找到,则应向用户显示错误,如“未找到”。我的代码用于展开下面的所有节点。有没有简单的方法来搜索jstree中的所有节点? <script type="text/javascript"> $(document).ready(function(){ $("#search_tree").click(function () { var value=document.getElementById("search_field").value; $("#tree").jstree("search",value); }); $("#tree").jstree({ "xml_data" : { "ajax" : { "url" : "jstree.xml" }, "xsl" : "nest" }, "themes" : { "theme" : "classic", "dots" : true, "icons" : true }, "search" : { "case_insensitive" : true, "ajax" : { "url" : "jstree.xml" } }, "plugins" : ["themes", "xml_data", "ui","types", "search"] }); }); </script> 我收到此错误: Instances[...] 为 null 或不是对象。这是一个 jstree 错误。有什么想法吗? 我已将这段代码添加到我的函数中: "search" : { "case_insensitive" : true, "ajax" : { "url" : "jstree.xml" } }, "plugins" : ["themes", "xml_data", "ui","types", "search"] 和 创建了此功能并与我的单击按钮相关联: function myFunction() { $(document).ready(function(){ var value=document.getElementById("search_field").value; $("#search_tree").click(function () { $("#tree").jstree("search",value) }); }); } 2023年,API逐年变化。使用版本v3.3.x, 这是我的工作代码: 创建jstree实例,配置如下: 当您搜索关键字时,请使用:


在具有 Open Liberty Dev 模式的 Maven 项目中使用本地库

我有一个 Maven 项目,它构建了一个部署到 Open Liberty 的战争。我正在使用 Liberty maven 插件: io.openliberty.tools 我有一个 Maven 项目,它构建了一个部署到 Open Liberty 的战争。我正在使用 Liberty maven 插件: <plugin> <groupId>io.openliberty.tools</groupId> <artifactId>liberty-maven-plugin</artifactId> <version>3.9</version> <!-- Specify configuration, executions for liberty-maven-plugin --> </plugin> 我正在利用开发模式并且它运行良好。但是,我想在 Dev 模式下使用本地 jar 文件库。 我期望我能够将 jar 文件放置在项目中的特定位置,并且 Liberty 开发模式会自动拾取它们 - 类似于自动拾取 server.xml 的方式src/main/liberty/config。我的 server.xml 设置为在此处查找库:${shared.config.dir}/lib/global,因此我尝试将罐子放入 src/main/liberty/shared/config/lib/global 中,但这不起作用。 我看到的另一种选择是使用 Libity 插件的 copyDependencies 配置。 有一些推荐的方法可以实现我想做的事情吗?理想情况下,我想要最简单的解决方案,既适用于 liberty dev 模式,也适用于 vanilla maven 构建 (mvn package)。 这里的类似问题利用了 copyDependencies 配置,但具体来说,我正在寻找本地 jar 的最佳解决方案(是的,我可以使用系统范围的 Maven 坐标或在本地安装 jar) 如何在 Maven 构建期间将外部依赖项复制到 Open Liberty 谢谢 好问题,稍微概括一下问题,您可能可以使用三种方法: 1.使用资源插件 <build> <resources> <!-- Explicitly configure the default too --> <resource> <directory>${project.basedir}/src/main/resources</directory> </resource> <!-- Custom library --> <resource> <directory>${project.basedir}/mylib</directory> <targetPath>${project.build.directory}/liberty/wlp/usr/shared/lib/global</targetPath> <!-- Default, but just emphasizing the point --> <filtering>false</filtering> </resource> </resources> 由于开发模式在其“生命周期”中调用 resources:resources 目标,因此可以在没有任何插件配置的情况下进行配置(使用“/project/build/resources”(在 XPath 术语中)元素),并使用您的 <targetPath>可以复制到任何位置。 2.添加到config目录(src/main/liberty/config) 除了src/main/liberty/config/server.xml处的主服务器XML配置文件之外,您还可以将其他文件和目录放在那里,所有文件和目录都将通过开发模式复制过来。 所以你可以创建,例如src/main/liberty/config/mylib/my.jar,它会被复制到target/liberty/wlp/usr/servers/defaultServer/mylib/my.jar。然后,您可以从 server.xml 将此位置引用为相对于服务器配置目录的 "mylib/my.jar"。 (这不太适合要求复制到“.../shared/lib/global”的原始用例,但可能适合其他查看此问题的人)。 3.添加系统范围的依赖项 这在原来的问题中已经提到过。我不太喜欢这个解决方案。为了完整起见,我会提及它,但请您自行查找详细信息。 这可能会很有趣。


如何在jetpack compose中使用浮动资源

我的浮点值是360F。我在 res/values 中创建了一个名为 float.xml 的文件。 浮动.xml 我的浮点值是 360F。我在 float.xml 中创建了一个名为 res/values 的文件。 float.xml <?xml version="1.0" encoding="utf-8"?> <resources> <item name="loading_circle_target" format="float" type="dimen">360</item> </resources> 然后像这样使用 @Composable fun LoadingCircle() { val currentRotation by transition.animateValue( 0F, targetValue = dimensionResource(id = R.dimen.loading_circle_target).value, // .. more code in here ) // more code in here } 我在这里遇到错误 android.content.res.Resources$NotFoundException: Resource ID #0x7f070346 type #0x4 is not valid at android.content.res.Resources.getDimension(Resources.java:766) at androidx.compose.ui.res.PrimitiveResources_androidKt.dimensionResource(PrimitiveResources.android.kt:79) 更新 我的最低sdk是21 如果您的目标至少是 API 29,则可以使用: val floatValue = LocalContext.current.resources.getFloat(R.dimen.loading_circle_target) @Composable fun LoadingCircle() { val currentRotation by transition.animateValue( 0F, targetValue = floatValue, // .. more code in here ) // more code in here } 我不得不恢复到旧的 is_phone bool,因为 booleanResource() 支持较旧的 API 级别。所以有 <resources> <bool name="is_phone">false</bool> </resources> 在 values-sw600dp 文件夹中并将其设置为正常值文件夹中的 true。然后就可以像这样使用了 @Composable fun LoadingCircle() { val currentRotation by transition.animateValue( 0F, targetValue = if (booleanResource(id = R.bool.is_phone)) 360f else 180f ) // more code in here }


如何在 Abap Simple Transformation 中添加 XML 命名空间

我使用简单转换从内部表中获取 XML。这是输出 XML。 我使用简单转换从内部表中获取 XML。这是输出 XML。 <?xml version="1.0" encoding="UTF-8"?> <Complement> <Document Doc="AAA"> <Locations> <Location> <Origin RFC="URE180429TM6"/> <Address Country="SOME_COUNTRY" /> [....] </Location> </Locations> <Products NumTotal="1"> <Product ValorProduct="12164501" /> [....] </Product> </Products> [....].... </Document> </Complement> 但是现在我需要做的是更改一些 XML 元素名称(重命名它们)..这应该使我的 XML 看起来像这样: 例如,我需要第一个元素(补语)看起来像 cfdi:Complement (在 cfdi 和补语之间使用冒号 :)...等等等等 <cfdi:Complement> <document:Document Doc="AAA"> <document:Locations> <document:Location> <document:Origin RFC="URE180429TM6"/> <document:Domicilio Country="NIGERIA" /> [....] </document:Location> </document:Locations> <document:Products NumTotal="1"> <document:Product ValorProduct="12164501" /> [....] </document:Product> </document:Products> [....].... </document:Document> </cfdi:Complement> 我一直在尝试直接从简单转换代码更改元素名称,但它不起作用: <?sap.transform simple?> <tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined"> <tt:root name="COMPLEMENT" type="ddic:ZCOMPLEMENT"/> <tt:template> <tt:namespace name="cfdi"/> <tt:namespace name="document"/> <cfdi:Complement> "<----- I get error from this lines <document:Document> "<----- I get error from this lines <tt:attribute name="Doc" value-ref=".COMPLEMENT.DOCUMENT.DOC"/> <document:Locations> <Location> <Origin> <tt:attribute name="RFC" value-ref=".COMPLEMENT.DOCUMENT.LOCATIONS.LOCATION.ORIGIN.RFC"/> [....] </Origin> <Address> <tt:attribute name="Country" value-ref=".COMPLEMENT.DOCUMENT.LOCATIONS.LOCATION.ADDRESS.COUNTRY"/> [....] </Address> </Location> </Locations> <Products> <tt:attribute name="NumTotal" value-ref=".COMPLEMENT.DOCUMENT.PRODUCTS.NUMTOTAL"/> <Product> <tt:attribute name="ValorProduct" value-ref="VALORPRODUCT"/> [....] </Product> </Products> [....].... </Document> </Complement> </tt:template> </tt:transform> 这些是我得到的错误: undeclared namespace prefix 'cfdi' 和 undeclared namespace prefix 'document' 这是简单的转换代码: 我只需要更改Element的名称即可。但我不认为这比看起来更难。 请帮我解决这个问题。我是这个 Abap 世界的新人。或者任何想法都会对我有很大帮助。问候 我之前遇到过一些命名空间问题,也许这个线程有帮助。 这是参考代码。正如您所看到的,您必须定义名称空间并按定义方式使用它,此处为 ns1。 <tt:template> <top_element xmlns:ns1="xsd/namespacesForBoxes" xmlns:ns2="xsd/namespacesForCartons" xmlns:ns3="xsd/namespacesForPallets"> <tt:namespace name="ns1"/> <tt:namespace name="ns2"/> <tt:namespace name="ns3"/> <tt:cond s-check="not-initial(ref('.telegram.BOX_ID'))"> <ns1:container> <tt:attribute name="box-id" value-ref=".telegram.BOX_ID"/> </ns1:container> </tt:cond> <tt:cond s-check="not-initial(ref('.telegram.CARTON_ID'))"> <ns2:container> <tt:attribute name="carton-id" value-ref=".telegram.CARTON_ID"/> </ns2:container> </tt:cond> <tt:cond s-check="not-initial(ref('.telegram.PALLET_ID'))"> <ns3:container> <tt:attribute name="pallet-id" value-ref=".telegram.PALLET_ID"/> </ns3:container> </tt:cond> </top_element> </tt:template> 之后应该是这样的: <top_element xmlns:ns1="xsd/namespacesForBoxes" xmlns:ns2="xsd/namespacesForCartons" xmlns:ns3="xsd/namespacesForPallets"> <ns1:container box-id="BOX"/> <ns2:container carton-id="CARTON"/> <ns3:container pallet-id="PALLET"/> </top_element> “tt:cond”只是为了让丢失的 XML 标签或不同顺序的标签不会扰乱你的转换。


使用 InertiaJs 和 Laravel 从数据库中删除用户

我在从数据库中删除记录时遇到问题。我正在使用 InertiaJS 和 Laravel。 组件代码 以下是链接/按钮代码: 我在从数据库中删除记录时遇到问题。我正在使用 InertiaJS 和 Laravel。 组件代码 以下是链接/按钮代码: <Link class="trash" @click="submit(result.ChildID)"> Move to Trash </Link> 注意: ChildID 是数据库中子记录的 id。 现在:当用户单击此链接时,将调用一个方法,如下所示。 methods: { submit: function (ChildID) { alert(ChildID) if (confirm("Are you sure you want to delete this child?")) { this.$inertia.delete('destroy/ChildID'); } }, }, 路线代码 Route::delete('destroy/{childID}',[childrenController::class,'destroy']); 控制器代码 public function destroy(children $childID){ $childID->delete(); return redirect()->route('View_Child_Profile'); } 现在,当我点击删除按钮时,我收到以下错误: 试试这个。我认为你犯了错误“this.$inertia.delete('destroy/ChildID');” methods: { submit: function (ChildID) { alert(ChildID) if (confirm("Are you sure you want to delete this child?")) { this.$inertia.delete(`destroy/${ChildID}`); // or this.$inertia.delete('destroy/'+ChildID); } }, }, 这是我处理删除过程的方式。 前视+惯性: import { Link } from '@inertiajs/inertia-vue3'; 在模板中: <Link method="delete" :href="route('admin.insta_feeds.destroy',id)">Delete</Link> 后端 Laravel: 路线: Route::resource('insta_feeds', InstaFeedsController::class); 控制器功能: public function destroy(InstaFeed $insta_feed) { if(isset($insta_feed->image_path)){ Storage::delete($insta_feed->image_path); } $insta_feed->delete(); return Redirect::route('admin.insta_feeds.index'); }


Laravel POST 方法返回状态:405 不允许在 POST 方法上使用方法

请查找以下信息: NoteController.php 请查找以下信息: NoteController.php <?php namespace App\Http\Controllers; use App\Http\Requests\NoteRequest; use App\Models\Note; use Illuminate\Http\JsonResponse; class NoteController extends Controller { public function index():JsonResponse { $notes = Note::all(); return response()->json($notes, 200); } public function store(NoteRequest $request):JsonResponse { $note = Note::create( $request->all() ); return response()->json([ 'success' => true, 'data' => $note ], 201); } public function show($id):JsonResponse { $note = Note::find($id); return response()->json($note, 200); } public function update(NoteRequest $request, $id):JsonResponse { $note = Note::find($id); $note->update($request->all()); return response()->json([ 'success' => true, 'data' => $note, ], 200); } public function destroy($id):JsonResponse { Note::find($id)->delete(); return response()->json([ 'success' => true ], 200); } } NoteRequest.php <?php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; class NoteRequest extends FormRequest { public function authorize() { return true; } public function rules() { return [ 'title', 'required|max:255|min:3', 'content', 'nullable|max:255|min:10', ]; } } Note.php(模型) <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Note extends Model { use HasFactory; protected $guarded = []; } api.php <?php use App\Http\Controllers\NoteController; use Illuminate\Support\Facades\Route; Route::prefix('v1')->group(function () { Route::resource('/note', NoteController::class); }); php artisan 路线:列表 GET|HEAD / ...................................................................................................................... POST _ignition/execute-solution ............... ignition.executeSolution › Spatie\LaravelIgnition › ExecuteSolutionController GET|HEAD _ignition/health-check ........................... ignition.healthCheck › Spatie\LaravelIgnition › HealthCheckController POST _ignition/update-config ........................ ignition.updateConfig › Spatie\LaravelIgnition › UpdateConfigController GET|HEAD api/v1/note .......................................................................... note.index › NoteController@index POST api/v1/note .......................................................................... note.store › NoteController@store GET|HEAD api/v1/note/create ................................................................. note.create › NoteController@create GET|HEAD api/v1/note/{note} ..................................................................... note.show › NoteController@show PUT|PATCH api/v1/note/{note} ................................................................. note.update › NoteController@update DELETE api/v1/note/{note} ............................................................... note.destroy › NoteController@destroy GET|HEAD api/v1/note/{note}/edit ................................................................ note.edit › NoteController@edit GET|HEAD sanctum/csrf-cookie .................................. sanctum.csrf-cookie › Laravel\Sanctum › CsrfCookieController@show 迅雷请求(同邮递员) JSON 请求 { "title": "Hello World", "content": "Lorem ipsum." } 尝试发出 JSON POST 请求并获取状态:405 方法不允许并且我正在使用 php artisan 服务,如果需要,我可以提供 GIT 项目。请告诉我。 您的验证规则看起来不正确。在您的 NoteRequest 类中,规则应该是一个关联数组,其中键是字段名称,值是验证规则。但是,在您的代码中,规则被定义为以逗号分隔的字符串列表。这可能会导致验证失败并返回 405 Method Not allowed 错误。 public function rules() { return [ 'title' => 'required|max:255|min:3', 'content' => 'nullable|max:255|min:10', ]; }


在发布为 npm 包之前使用 npm 链接测试组件时出现重复的 ReactJS 导入问题

我有一个像这样的简单组件。 从'react'导入React,{useState}; 函数 MyComponentWithState(props) { const [值,setValue] = useState(0); 返回 ( 我的价值... 我有一个像这样的简单组件。 import React, {useState} from 'react'; function MyComponentWithState(props) { const [value, setValue] = useState(0); return ( <p>My value is: {value}</p> ) } export default MyComponentWithState; 我想将它作为单独的包发布在 NPM 上。因此,为此我准备了 package.json 和 webpack.config.js,如下所示。 package.json: { "name": "try-to-publish", "version": "0.0.1", "description": "Just a test", "main": "build/index.js", "scripts": { "start": "webpack --watch", "build": "webpack" }, "author": { "name": "Behnam Azimi" }, "license": "ISC", "peerDependencies": { "react": "16.9.0", "react-dom": "16.9.0" }, "dependencies": { "react": "16.9.0", "react-dom": "16.9.0", "prop-types": "15.7.2", "react-scripts": "3.1.1", "webpack": "4.39.3" }, "devDependencies": { "@babel/core": "7.6.0", "@babel/plugin-proposal-class-properties": "7.5.5", "@babel/preset-env": "7.6.0", "@babel/preset-react": "7.0.0", "babel-loader": "8.0.6", "babel-plugin-transform-object-rest-spread": "6.26.0", "babel-plugin-transform-react-jsx": "6.24.1", "css-loader": "3.2.0", "node-sass": "4.12.0", "sass-loader": "8.0.0", "style-loader": "1.0.0", "webpack-cli": "3.3.8", "webpack-external-react": "^1.1.2" } } webpack.config.json: const path = require('path'); module.exports = { entry: './src/index.js', output: { path: path.resolve(__dirname, 'build'), filename: 'index.js', libraryTarget: 'commonjs2' }, module: { rules: [ { test: /\.(js|jsx)$/, exclude: /node_modules/, include: path.resolve(__dirname, 'src'), use: { loader: "babel-loader" } }, ] }, resolve: { alias: { 'react': path.resolve(__dirname, 'node_modules/react'), 'react-dom': path.resolve(__dirname, 'node_modules/react-dom'), } }, externals: { 'react': "commonjs react", 'react-dom': "commonjs react-dom" }, }; 这是我的 .babelrc: { "presets": [ "@babel/preset-env", "@babel/preset-react" ], "plugins": ["@babel/plugin-proposal-class-properties"] } 当我将组件发布到 NPM 并使用 `npm install 将其安装到我的另一个 ReactJs 项目中时,这些配置就像魅力一样,但我的观点是本地测试! 我想在发布之前测试这个组件/库。为此,我使用 npm link 功能将我的组件与我的主 ReactJS 项目链接起来。 正如您在上面看到的,我的组件是功能性的,我也使用了钩子。因此,当我将本地链接的库注入到我的主 ReactJs 项目中时,会遇到此错误, 无效的挂钩调用。钩子只能在函数组件的主体内部调用。发生这种情况可能是由于以下原因之一: 1.您的React和渲染器版本可能不匹配(例如React DOM) 2. 你可能违反了 Hooks 规则 3. 您可能在同一个应用程序中拥有多个 React 副本 我的问题与第三个原因有关。我的项目使用 ReactJs 并导入一次,我的组件也会导入 React!我的意思是在一个项目中两次 React 导入!. 我的 Webpack 配置中还有关于 react 和 react-dom 的 externals 配置。 我应该怎么做才能解决这个问题?我的错误在哪里? 更新: 我也尝试过 @sung-m-kim 和 @eddie-cooro 所说的,但没有成功!意思是,我更改了 package.json 并从 react 中删除了 react-dom 和 dependencies 并将它们添加到 devDpendencies。 我终于通过这些步骤解决了这个问题。 运行npm链接里面 <your-library-package>/node_modules/react 还有 运行npm链接里面 <your-library-package>/node_modules/react-dom 然后在 应用程序根目录中运行 npm link react 和 npm link react-dom 并且不要忘记将 React 和 React-dom 作为库中的外部对象保留 // webpack.config.js const externals = { "react": "react", "react-dom": "react-dom", } module.exports = { . . . externals } 我解决了我的问题。我使用 RollupJS 而不是 Webpack 作为捆绑工具进行捆绑。 这是我的rollup.config.js: import {uglify} from 'rollup-plugin-uglify' import babel from 'rollup-plugin-babel' export default { input: "./src/index.js", external: ['react', 'react-dom'], output: { name: 'test-lib', format: "cjs", }, plugins: [ babel({ exclude: "node_modules/**" }), uglify(), ], }; 和我的package.json: { "name": "test-lib", "version": "1.0.0", "main": "dist/test-lib.min.js", "scripts": { "build": "rollup -c -o dist/test-lib.min.js" }, "author": "Behnam Azimi", "license": "ISC", "peerDependencies": { "react": "^16.9.0", "react-dom": "^16.9.0" }, "devDependencies": { "@babel/core": "^7.6.0", "@babel/preset-env": "^7.6.0", "@babel/preset-react": "^7.0.0", "rollup": "^1.21.4", "rollup-plugin-babel": "^4.3.3", "rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-uglify": "^6.0.3" } } 经过这些更改,npm link在我的ReactJS(Hooks)项目中真正发挥了作用。 请注意,这只是一个简单的 Rollup 配置来展示我的解决方案,您可以在配置中添加多种内容,例如热重载、样式加载器和许多其他插件。 仅在 package.json 的 react 部分(而不是 react-native)内设置 peerDependencies 和 dependencies 包。另外,对于本地开发(当您的包未包含在任何其他 React 项目中并且您想在本地运行它时),您可以使用 devDependencies 字段。 我在打字稿反应项目中解决了这个问题。 可能,当使用 npm link 时,请使用主应用程序项目和组件项目中的 react。 因此,在您的 package.json 中从 react 和/或 dependencies 中删除 devDependencies 检查答案:https://stackoverflow.com/a/62807950/5183591 我也有同样的问题。 就我而言,我开发了一些 UI 组件作为包,其中有一个包含 React 应用程序的示例文件夹,用于创建 React 应用程序。 问题是,当我使用 npm i ../ 将包安装到示例应用程序中时,它会将包中的所有文件安装到示例应用程序中,包括 node_modules 文件夹。由于我已经安装了 react 和 react-dom 作为对等依赖项,示例应用程序现在有两个不同的 React 副本。 从包中删除 node_module 文件夹并重新安装包再次解决了我的问题。


© www.soinside.com 2019 - 2024. All rights reserved.