[英]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#95和pr#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: 请注意此解决方案:
/* tslint:disable */
to the top of the file. /* tslint:disable */
。 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.