angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Angular 2 Cli - Import of Socket.IO - module not found

Open REPTILEHAUS opened this issue 10 years ago • 5 comments

Please provide us with the following information:

OS?

Mac OSX Sierra

Versions.

angular-cli: 1.0.0-beta.16 node: 6.7.0 os: darwin x64

Repro steps.

Yes.. I have made a few components. The issue lies where I try to import the socket.io-client library from node_modules, I get the following error on the terminal:

ERROR in [default] /Applications/MAMP/htdocs/foldername/project-socketio/client/src/app/chat.service.ts:5:20 Cannot find module 'socket.io-client/socket.io'.

The Component/Service file I am trying to import it to looks like this, I have reduced the code for brevity:

import { Injectable } from '@angular/core'; import { Subject } from 'rxjs/Subject'; import { Observable } from 'rxjs/Observable'; import * as io from 'socket.io-client';

--- In polyfills.ts file I added this line import 'socket.io-client/socket.io';

and typings.json file:

{ "globalDependencies": { "socket.io-client": "registry:dt/socket.io-client#1.4.4+20160317120654" } }

I installed typings: npm install --save @types/socket.io-client

I also added this to the angular-cli.json file: "scripts": ["../node_modules/socket.io-client/socket.io.js"],

Not sure what else I can do.. I used to use systemjs.config for pulling in 3rd party libs but I see that this ngCli uses webpack.. is there another step I should be taking....

The log given by the failure.

Normally this include a stack trace and some more information.

Mention any other details that might be useful.


Thanks! We'll be in touch soon.

REPTILEHAUS avatar Oct 23 '16 23:10 REPTILEHAUS

Try add to src/typings.d.ts this line before declare var System: any;

/// <reference path="../typings/index.d.ts" />

bruha avatar Oct 25 '16 10:10 bruha

Cheers, In the end it started working and in typical developer fashion: it doesnt work, I have no idea why.... it works, I have no idea why

Possibly because the last attempt I used Yarn as a package manager to reinstall the dep's rather thatn NPM... I'll keep this in mind though if I ever come across it again. Cheers

REPTILEHAUS avatar Oct 25 '16 23:10 REPTILEHAUS

Closing as it seems resolved.

filipesilva avatar Nov 02 '16 17:11 filipesilva

He working

zetsu01 avatar Dec 08 '18 13:12 zetsu01

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.