在项目中使用lint-stafed
进行代码格式化和检查时,报错:
D:\Projects\my-app\node_modules\any-observable\register.js:29
throw new Error('Cannot find any-observable implementation nor' +
^
Error: Cannot find any-observable implementation nor global.Observable. You must install polyfill or call require("any-observable/register") with your preferred implementation, e.g. require("any-observable/register")('rxjs') on application load prior to any require("any-observable").
at loadImplementation (D:\Projects\my-app\node_modules\any-observable\register.js:29:9)
at D:\Projects\my-app\node_modules\any-observable\loader.js:30:18
at Object.<anonymous> (D:\Projects\my-app\node_modules\any-observable\index.js:2:39)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (D:\Projects\my-app\node_modules\@samverschueren\stream-to-observable\index.js:2:20)
网上有如下几种解决方案:
- 删除
node_modules
和package-lock.json
,重新执行npm install
; - 安装依赖
npm install rxjs-compat
; - 将
list-staged
模块更新至最新版 ;
但是三种方式尝试后,我的报错还是没有解决,遂取寻找源头查看原代码:
很明显,是变量 imp1 不存在时报错,根据源码尝试安装插件:执行
npm install rxjs
后,报错消失,代码正常运行。