简体   繁体   English

SharePoint Framework中的反射元数据突然中断

[英]Reflect-metadata suddenly breaking in Sharepoint Framework

I wrote an NPM module for use in my SharePoint Framework webpart that uses reflect-metadata 我编写了一个NPM模块,用于在我的SharePoint Framework Webpart中使用reflect-metadata

import "reflect-metadata";

export function someDecorator(name: string): ClassDecorator {
    return target => {
        Reflect.defineMetadata("MyDecorator", name, target);
    }
}

This was using fine for a few months until yesterday my spfx app suddenly started failing with: 几个月来一直很好用,直到昨天我的spfx应用突然开始失败,并显示以下信息:

NonErrorEmittedError: (Emitted value instead of an instance of Error) Cannot find source file 'Reflect.ts': Error: Can't resolve './Reflect.ts' in '/mnt/tmp/my-webpart/node_modules/reflect-metadata'
    at emitWarning (/mnt/tmp/my-webpart/node_modules/webpack/lib/NormalModule.js:117:16)
    at /mnt/tmp/my-webpart/node_modules/source-map-loader/index.js:64:7
    at onError (/mnt/tmp/my-webpart/node_modules/enhanced-resolve/lib/Resolver.js:65:10)
    at loggingCallbackWrapper (/mnt/tmp/my-webpart/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at runAfter (/mnt/tmp/my-webpart/node_modules/enhanced-resolve/lib/Resolver.js:158:4)
    at innerCallback (/mnt/tmp/my-webpart/node_modules/enhanced-resolve/lib/Resolver.js:146:3)
    at loggingCallbackWrapper (/mnt/tmp/my-webpart/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at next (/mnt/tmp/my-webpart/node_modules/tapable/lib/Tapable.js:252:11)
    at /mnt/tmp/my-webpart/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:40:4
    at loggingCallbackWrapper (/mnt/tmp/my-webpart/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at runAfter (/mnt/tmp/my-webpart/node_modules/enhanced-resolve/lib/Resolver.js:158:4)
    at innerCallback (/mnt/tmp/my-webpart/node_modules/enhanced-resolve/lib/Resolver.js:146:3)
    at loggingCallbackWrapper (/mnt/tmp/my-webpart/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at next (/mnt/tmp/my-webpart/node_modules/tapable/lib/Tapable.js:252:11)
    at innerCallback (/mnt/tmp/my-webpart/node_modules/enhanced-resolve/lib/Resolver.js:144:11)
    at loggingCallbackWrapper (/mnt/tmp/my-webpart/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)

That's from building the exact same code that was just working fine two days ago. 那是因为建立了与两天前正常工作的完全相同的代码。

So what could cause this? 那是什么原因造成的呢? Why is it suddenly looking for a non-existent Reflect.ts file? 为什么突然寻找不存在的Reflect.ts文件? And, most importantly, how can I get it working again? 而且,最重要的是,如何使它重新工作?

If you manually add Reflect.ts to /node_modules/reflect-metadata your build should succeed. 如果您将Reflect.ts手动添加到/node_modules/reflect-metadata构建应会成功。

See issue#95 and pr#89 参见issue#95pr#89

I opted to copy Reflect.ts into my source code and import this local file instead of "reflect-metadata" . 我选择将Reflect.ts复制到我的源代码中,然后导入此本地文件而不是"reflect-metadata"

Note with this solution: 请注意此解决方案:

  1. tslint warnings occurred so I added /* tslint:disable */ to the top of the file. 发生tslint警告,因此我在文件顶部添加了/* tslint:disable */
  2. ts error is in file "Type 'symbol' cannot be used as an index type." ts错误在文件“类型'symbol'不能用作索引类型”中。 due to the TS version spfx uses vs the version reflect-metadata uses. 由于TS版本spfx使用vs版本反射元数据使用。 I replaced map[key] with map[key as string | number] 我将map[key]替换为map[key as string | number] map[key as string | number] to get rid of error. map[key as string | number]摆脱错误。

Alternatively, you could fork reflect-metadata and release an updated npm module that includes Reflect.ts. 或者,您可以派生反射元数据并发布包含Reflect.ts的更新的npm模块。

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

相关问题 Angular2 RC-4迁移失败,带有反射元数据 - Angular2 RC-4 migration failing with reflect-metadata 未在反射元数据上定义需求-__webpack_require__问题 - Require is not defined on reflect-metadata - __webpack_require__ issue Angular2使用npm reflect-metadata或core-js / es7 / reflect - Angular2 using either npm reflect-metadata or core-js/es7/reflect Nestjs 错误导入“reflect-metadata”无法在模块外使用导入语句 - Nestjs error import "reflect-metadata" Cannot use import statement outside a module 将ES6与Angular2 rc3一起使用时,需要使用未捕获的反射元数据填充程序 - Uncaught reflect-metadata shim is required when using ES6 with Angular2 rc3 Angular2无法更新到RC7-zone.js和reflect-metadata - Angular2 Failing to update to RC7 - zone.js & reflect-metadata 如何使用Angular 2(beta和更新版本)加载RxJS(和zone.js / reflect-metadata)? - How to load RxJS (and zone.js / reflect-metadata) with Angular 2 (beta and newer)? Natviescript中的单元测试Angular:使用类装饰器时需要reflect-metadata shim - Unit Testing Angular in Natviescript: reflect-metadata shim is required when using class decorators 如何在 Systemjs 构建器任务中包含 zone.js、reflect-metadata 等? - How to include zone.js, reflect-metadata etc. in Systemjs builder task? SharePoint 2013列表新表单不反映修改后的更改 - SharePoint 2013 List newform does not reflect modified changes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM