2

I would like to import file-system npm library to my Angular 2 project and strictly followed these steps: https://medium.com/@s_eschweiler/using-external-libraries-with-angular-2-87e06db8e5d1#.1dx1fkiew

Now it's done I have the following basically error and really don't know how am I suppose to import simple npm module to Angular 2 project...

src/app/app.component.ts(2,21): error TS2307: Cannot find module 'file-system'

Here's my app.component.ts file:

import { Component } from '@angular/core';
import * as fs from 'file-system';

@Component({
selector: 'my-app',
templateUrl: 'app/folio.html'
})
export class AppComponent  { 
  name = 'Angular'; 
  src = './app/img/';
  dir = fs.readdirSync(src);
}

I tried something related with typings :

typings install file-system

but the module isn't find by typings to be installed.

Does anyone have a solution or know a good tutorial to include any npm modules in Angular 2 project ?

5
  • When hovering over 'file-system' in your import statement does it show you the path to the npm module? Commented Feb 19, 2017 at 17:47
  • Did the npm install work without errors (do you have a folder node_modules/file-system/ with all files in it)? Did tsd install succeed? Commented Feb 19, 2017 at 18:11
  • You're likely going to have problems using any fs related modules in angular. Commented Feb 19, 2017 at 19:17
  • @KonstantinA.Magg Yes for npm install, tsd install just tells me there's nothing. Commented Feb 20, 2017 at 1:04
  • @J.AdamConnor It tells me this: [ts] Could not find a declaration file for module 'file-system'. '[...]/quickstart/node_modules/file-system/file-system.js' implicitly has an 'any' type. Though I have the file in the right place and did the right things in systemjs.config.js. Commented Feb 20, 2017 at 1:14

1 Answer 1

0

npm install @types/file-system --save

Typings is deprecated. You should install straight from NPM.

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

2 Comments

Can you be more specific. What exactly is the error.
"npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "@types/file-system" "--sa" this is hte first one among others that I can"t copied

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.