简体   繁体   中英

Cannot find module '@angular/forms'

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?

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

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...

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.

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.

The way to solve problem is: use cmd npm install @angular/forms --save

and go to package.json double check make sure @angular/forms: "YOUR VERSION", => save it

reset the IDE tool and go back to app.module.ts remove and retype again. it much be work.

Thank You

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
    ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM