Angular-cli: Cannot find module 'underscore'.

Created on 12 Feb 2017  路  8Comments  路  Source: angular/angular-cli

I am trying to include Underscore "underscore": "^1.8.3"
and I get this error Cannot find module 'underscore'.

This is how I try to import it.
import * as _ from 'underscore';

I went online to look for a solution which there where many from last year by including it in the system-config.js and typings.json files. However I do not have these files in my project. I guess they are no longer provided.

Is there a current solution for importing underscore?

This is the first time to report an issue so hopefully my issue makes sense

Thanks,
Jesse Soldat

Most helpful comment

npm install -g typescript@next
And then

npm install --save underscore
npm install --save @types/underscore

This worked for me. Thanks everyone

All 8 comments

@JesseSoldat :
I am new to this project, but it looks like Lodash already exists in this project . Maybe you could just use that ?

If you have a recent Angular CLI project you should be able to fix this by running this:

$ npm install --save-dev @types/underscore

Typings have been replaced by @types and SystemJS is no longer used by apps created by Angular CLI - these now use WebPack.

Closing this as answered.

npm install -g typescript@next
And then

npm install --save underscore
npm install --save @types/underscore

This worked for me. Thanks everyone

@JesseSoldat's solution worked for me. Wish someone could explain why.

cl;lfcf

Thank you!

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings