10

I'm developing an Ionic 2/Angular app and I'm trying to use form validation following this tutorial: https://angular.io/docs/ts/latest/cookbook/dynamic-form.html

But the compiler says:

Cannot find module '@angular/forms'.

Why is this modules not available? Is it deprecated?

6
  • 1
    Does systemjs.config.js contain @angular/forms reference? I mean, do you load it through systemjs ? Commented Jul 19, 2016 at 18:30
  • No, I didn't. It doesn't contains a systemjs.config.js and it is not even available at node_modules/@angular. Does I need to install it from npm? It's an Ionic 2 templated installed via 'ionic start' command ans uses gulp. Commented Jul 19, 2016 at 18:41
  • Sorry I'm not an ionic guy. Better to wait for others to reply. Commented Jul 19, 2016 at 18:48
  • Although it's an Ionic 2 project I think the Angular thing must be similar. Inside the node_modules/@angular folder should not be a forms folder? – Natanael 16 secs ago edit Commented Jul 19, 2016 at 18:51
  • Which version of Angular2 do you use? Commented Jul 19, 2016 at 19:39

6 Answers 6

12

Try npm install @angular/forms --save

It will warn you that you should be using 2.0.0-rc.4 though. This may come with it's own set of upgrade challenges...

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

Comments

10

I ran into the same problem, my solution was:

1) add forms to the package.json:

"dependencies": {
...
"@angular/forms":   "0.2.0",
...
}

2) install using npm in the console, type within the app folder

npm install

3) run app again

npm start

Hope this helps

1 Comment

Vielen Dank Mein Freund :) !
3

Run this command npm install @angular/forms --save

Go to package.json and double check to make sure this dependency is present @angular/forms: "{your version}", and save the changes.

Close and reopen your IDE and go back to app.module.ts. Remove the import statement and retype it again, then it should work.

Thank You

2 Comments

I would just like to say that I found this post as I was running into this issue in a recent project. Your comment about go back and retyping worked for me. I would cut and past the line with the issue. Save and then paste the line back in. Fixed the issue. Thanks for the suggestion.
This worked for me also. I did not need to close my IDE or save (--save does that). After running the install command and retyping the last part of the import statement it worked for me. Made a suggested edit to your answer.
0

Sometimes when updating versions I see messages like this:

npm ERR! errno -4048
npm ERR! syscall rename
npm ERR! Error: EPERM: operation not permitted, rename 'R:\TFS\RRCRM\RRCRM\node_modules\@angular\forms' -> 'R:\TFS\RRCRM\RRCRM\node_modules\@angular\.forms.DELETE'
npm ERR!     at Error (native)
npm ERR!  { [Error: EPERM: operation not permitted, rename 'R:\TFS\RRCRM\RRCRM\node_modules\@angular\forms' -> 'R:\TFS\RRCRM\RRCRM\node_modules\@angular\.forms.DELETE']
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'rename',
npm ERR!   path: 'R:\\TFS\\RRCRM\\RRCRM\\node_modules\\@angular\\forms',
npm ERR!   dest: 'R:\\TFS\\RRCRM\\RRCRM\\node_modules\\@angular\\.forms.DELETE',
npm ERR!   parent: 'rrcrm' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Please include the following file with any support request:
npm ERR!     R:\TFS\RRCRM\RRCRM\npm-debug.log

I belive it can be due to file in use errors sometimes (I'm running Visual Studio on Windows as administrator).

Make sure nothing is running that might have a file lock on any packages - such as angular CLI. So close any windows or processes and run something like npm install again.

Comments

-1

I had a weird situation where I can not do npm install, and had to copy the libs from shared path. Copy the "forms" folder under node_modules/@angaular solved the issue.

Comments

-3

Is import { FormsModule } from '@angular/forms'; is injected in app.module.ts and added FormsModule array in the imports as below

    app.module.ts
    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { FormsModule } from '@angular/forms';


    imports: [
      BrowserModule,
      FormsModule
    ]

Comments

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.