6
votes

I am following the NativeScript tutorial here:

Native Script Angular - Chapter 3

I'm having an error when trying to import nativescript-angular/http. it says Cannot find module 'nativescript-angular/http'. Am I missing anything? I noticed that there is not http.js under node_modules/native-script-angular/http.js.

enter image description here

Any help would be appreciated.

5
Did you try to install npm packages? - scokmen
Hello scokmen, not sure what you mean by that, but I followed the tutorial and installed NativeScript through NPM. So I guess the npm packages are installed, right? - PinoyCoder
In the root of your project run npm i? - George Edwards
Also, do you have a references file? - George Edwards
I tried this @GeorgeEdwards but it didn't do anything. - PinoyCoder

5 Answers

6
votes

I am pretty sure that the version of Angular you are using are no longer support 'http' service, try to use 'http-client' instead.

import { NativeScriptHttpClientModule } from "nativescript-angular/http-client";

Or use Angular version 5 or older.

3
votes

You include in file app.module.ts next "NativeScriptHttpModule" enter image description here

0
votes

I had a similar issue. All I had to do was to remove package-lock.json file along with my node_modules folder and npm install after that.

0
votes

Trying to look for NativeScriptHttpClientModule was not quite enough to fix this for me. I additionally had to remove the '/http' from the end. It's able to find the module in the 'nativescript-angular' directory without the reference to the sub directory.

import { NativeScriptHttpClientModule } from "nativescript-angular"
-1
votes

From within your groceries folder you just need to run the following commands to update the version.

$ npm install -g npm-check-updates
$ npm-check-updates -u
$ npm install 

When package.json updated to the following it worked for me

  "dependencies": {
"@angular/common": "2.0.0-rc.5",
"@angular/compiler": "2.0.0-rc.5",
"@angular/core": "2.0.0-rc.5",
"@angular/http": "2.0.0-rc.5",
"@angular/platform-browser": "2.0.0-rc.5",
"@angular/platform-browser-dynamic": "2.0.0-rc.5",
"@angular/platform-server": "2.0.0-rc.5",
"@angular/router": "3.0.0-rc.1",
"tns-core-modules": "2.2.1",
"nativescript-angular": "0.3.1"
},

If you compare the version you will see that NS _HTTP_PROVIDERS is within the current master but not version 2.0.0 that is included with the sample

https://github.com/NativeScript/nativescript-angular/blob/master/nativescript-angular/http/ns-http.ts