我编写了一个NPM模块,用于我的SharePoint Framework webpart,使用reflect-metadata
import "reflect-metadata";
export function someDecorator(name: string): ClassDecorator {
return target => {
Reflect.defineMetadata("MyDecorator", name, target);
}
}
直到昨天,我的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)
构建两天前工作正常的完全相同的代码。
那么是什么导致这个?为什么它突然寻找不存在的Reflect.ts
文件?而且,最重要的是,我怎样才能让它再次运作?
答案 0 :(得分:1)
如果您将Reflect.ts手动添加到/node_modules/reflect-metadata
,则构建应会成功。
我选择将Reflect.ts复制到我的源代码中,然后导入此本地文件而不是"reflect-metadata"
。
注意此解决方案:
/* tslint:disable */
。map[key]
取代了map[key as string | number]
,以消除错误。或者,您可以派生反射元数据并发布包含Reflect.ts的更新的npm模块。