Given that we're trying to reference Lodash in an Angular project to be built using ng-packagr, we're getting the following error:
error TS2686: '_' refers to a UMD global, but the current file is a module. Consider adding an import instead.
This suggests to me that it's not correctly picking up the typescript definitions file we have set up.
The error only occurs when using ng-packagr to build. When using ng-serve to test the demo app it works fine.
typings.d.ts
/* SystemJS module definition */
declare var module: NodeModule;
interface NodeModule {
id: string;
}
// lodash global typing - begin
declare namespace _ {
}
// lodash global typing - end
I've seen various issues on ng-packagr's github page talking about using externals or embedded, but the documentation is pretty sparse and experimentation in this area hasn't yielded any leads for me to follow.
I've seen this snippet pop up a few times, which appears to accurately reference the correct path.
ng-package.json
...
"externals": {
"lodash": "./node_modules/lodash/index.js"
},
...
Anyone got any ideas how I might debug and investigate this?
I've found a workaround for this problem but I'm unsatisfied with the solution.
In the following link, ng-packagr's author recommends using a triple slash reference to reference the .d.ts.