1

I'm unable to import from a non angular module.

app.components.ts

Folder

Node_Modules -> array- slice

import {array-slice}from 'array-slice' <- Doesn't work

import {Http,Response} from '@angular/http' <-- Works

1 Answer 1

3

try

 import slice = require('array-slice');

the { Http, Response } syntax only works for es6 modules with multiple named exports. The following would also work in typescript

import * as slice from 'array-slice'

but read details here about why this is not the best approach - New es6 syntax for importing commonjs / amd modules i.e. `import foo = require('foo')`

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. I keep getting a TS2307: Cannot find module 'array-slice'
That module is present under node_modules (library root)
Thanks for all your help, I realized that I wasn't using reconfigure.json in my typescript setting in webstorm.
great - in case anyone else has a similar problem the cannot find module error is usually related to node modules without type definition files - other possible solutions here - stackoverflow.com/questions/37000981/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.