typescript - How to resolve error "Cannot find name '_' " using lodash in angular2 app with webpack -
here's how import lodash in typescript/angular2 app using webpack:
- $ npm install lodash --save
- $ typings install dt~lodash --save
in webpack.config.js:
module.exports = { plugins: [ new provideplugin({ '_' : 'lodash'
and works.
but there's still error in editor (sublime) , in terminal on runtime : cannot find name '_'
so, i'm missing?
in .ts file use lodash tried declare so:
declare var _ : lodashstatic
with no luck.
i not sure how old issue these kind of issues still happening. have added lodash type definition angular-cli project , made work. part of experiment wanted third party libraries used inside angular2. had struggle bit figure out how works here goes.
the current type definition lodash seems having issue. getting error while compiling. replaced content of type definition file older version of lodash type definition file , worked. working version path,
https://github.com/borisyankov/definitelytyped
i installed lodash typings install dt~lodash --save
once add type definition file, reference in base type definition file shown below.
now if miss refer base file in tsconfig.json, won't have lodash module available in angular2. can add below,
to use lodash feature import module can see if open type definition file. in case of lodash it's "lodash".
in components can import librabries like,
import * $ 'jquery'; import * _ "lodash";
and use features in code,
eg:
and result is,
Comments
Post a Comment