Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use underscore.js with webpack

I would like to use underscore in my Typescript Aurelia application. I created a typescript file where i put:

import * as _ from 'underscore'

but VS Code says:

[ts] Cannot find module 'underscore'

I have put this into webpack.config:

plugins:[
    new webpack.ProvidePlugin({
      underscore:'underscore'
    })  
]

Also i have installed underscore using:

npm install --save underscore

what else must I do to get it to work?

like image 393
Luka Avatar asked Mar 18 '26 13:03

Luka


1 Answers

Since you are working with TypeScript, you must also install a *.d.ts typings file for underscore. Try running:

npm install --save @types/underscore

This lets TS know about the underscore module and its interfaces.

Here's some more information about typings management with Typescript

like image 158
Matt Bierner Avatar answered Mar 20 '26 06:03

Matt Bierner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!