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

fullyconnected
  • 59
  • 1
  • 1
  • 6

1 Answers1

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')`

Community
  • 1
  • 1
glendaviesnz
  • 1,889
  • 14
  • 12
  • Thank you. I keep getting a TS2307: Cannot find module 'array-slice' – fullyconnected Feb 22 '17 at 04:19
  • That module is present under node_modules (library root) – fullyconnected Feb 22 '17 at 04:21
  • Thanks for all your help, I realized that I wasn't using reconfigure.json in my typescript setting in webstorm. – fullyconnected Feb 22 '17 at 04:30
  • 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 - http://stackoverflow.com/questions/37000981/how-to-import-node-module-in-typescript-without-type-definitions – glendaviesnz Feb 22 '17 at 04:36