Nativescript Cannot find module 'nativescript-angular/http'
Asked Answered
C

7

6

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.

Coe answered 26/8, 2016 at 1:52 Comment(8)
Did you try to install npm packages?Newman
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?Coe
In the root of your project run npm i?Hilarity
Also, do you have a references file?Hilarity
I tried this @GeorgeEdwards but it didn't do anything.Coe
Sorry, i ran the npm i on a different directory. I have tried this (on the right directory), and it kind of refreshed the node_modules path. But it still gives me the error. Based on the tutorial, http module should be found under nativescript-angular folder. Is this an oversight on the tutorial? should I copy the http modules from node_modules folder to the nativescript-angular folder?Coe
What version of nativescript-angular do you have installed? Do you get this error when you run tsc or tns build ? Sometimes the intellisense just gets a bit confused. I'd also try deleting and reinstalling the node_modules just to be sure nothing is corrupted. Also, what OS are you working on?Hilarity
I often find these "Can't find module X" errors within nativescript are fixed via deleting platforms, hooks and node_modules and running npm install again.Tav
W
6

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.

Wynny answered 11/9, 2018 at 14:27 Comment(0)
L
3

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

Logia answered 6/11, 2017 at 19:38 Comment(0)
D
1

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"
Doolie answered 7/12, 2020 at 17:10 Comment(1)
Look into node_modules. With version 8, the name of package is changed so Change import { platformNativeScriptDynamic } from "nativescript-angular/platform"; to import { platformNativeScriptDynamic } from "@nativescript/angular"; I was migrating from V7 to V8 NativeScriptHuntingdon
D
0

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.

Dissension answered 2/11, 2017 at 15:25 Comment(0)
L
0

Please upgrade your angular and nativescript to the current version; I can help you do that if you are stuck

Lief answered 22/10, 2021 at 17:24 Comment(0)
H
0

In your component

import {HttpClient, HttpHeaders, HttpParams} from "@angular/common/http";

In app.module

import { NativeScriptHttpClientModule } from "nativescript-angular/http-client";
imports: [NativeScriptHttpClientModule]
Hieronymus answered 25/1, 2022 at 9:58 Comment(0)
P
-1

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

Pavier answered 30/8, 2016 at 14:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.